Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Problem Use Api Rate Topic   - - - - -

 
  • masoud_tesna
  • Advanced Member
  • Trial users
  • Join Date: 27-Jun 19
  • 61 posts

Posted 07 February 2021 - 05:38 PM #1

When using a different domain to use API and fetch data, I receive the following Error:
 
"Access-Control-Allow-Origin"
 
 
k50c_screen_shot_2021-02-07_at_8.50.39_p
 
 
vqbt_screen_shot_2021-02-07_at_9.05.46_p
 
 
I need your guidance regarding this problem...
 
Thank You
 
my code:
 
    const url = "https://hornb2b.com/api/products?items_per_page=4&company_id=181";

    let headers = new Headers();
    headers.append('Access-Control-Allow-Origin', '*');
    headers.append('Access-Control-Allow-Credentials', 'true');
    headers.append('authority', 'hornb2b.com');
    headers.append("Authorization", `Basic ${auth}`);
    headers.append('Content-Type', 'application/json');
    headers.append('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9');

    fetch(url, {
      method:'GET',
      headers: headers
    })
    .then(response => response.json())
    .then(
      (json) => {
        /*console.log(json);*/
        this.setState({
          isLoaded: true,
          products: json.products
        });
      },
      // Note: it's important to handle errors here
      // instead of a catch() block so that we don't swallow
      // exceptions from actual bugs in components.
      (error) => {
        this.setState({
          isLoaded: true,
          error
        });
      }
    )

 

Attached Thumbnails

  • Screen Shot 2021-02-07 at 8.50.39 PM.png
  • Screen Shot 2021-02-07 at 9.05.46 PM.png


 
  • masoud_tesna
  • Advanced Member
  • Trial users
  • Join Date: 27-Jun 19
  • 61 posts

Posted 09 February 2021 - 01:45 PM #2

my cs-cart url: hornb2b.com

 

get api by react project in : hornb2b.com/store-test

Fetch api is done without "Access-Control-Allow-Origin" error.

api get without  "Access-Control-Allow-Origin" error...

but store.hornb2b.com "Access-Control-Allow-Origin" error and not fetch api

please help me...