0

Issue:

I'm trying to make a JSONP request using ajax, but I'm encountering the below error.

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://nftrade.com/_next/data/_Mat1YwGAWWtzBCNmnbbI/assets/avalanche/0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4/2493.json?chainName=avalanche&contractAddress=0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4&tokenID=2493&callback=jQuery341041842279918868885_1645936498754&_=1645936498755 with MIME type application/json.

The below URL works when I access the it using a chrome browser:

URL:

https://nftrade.com/_next/data/_Mat1YwGAWWtzBCNmnbbI/assets/avalanche/0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4/2493.json?chainName=avalanche&contractAddress=0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4&tokenID=2493

This is the response headers that is returned from the browser:

Response Headers

  • cache-control: private, no-cache, no-store, max-age=0, must-revalidate
  • cf-cache-status: DYNAMIC
  • cf-ray: 6e3ec0558e647150-YUL
  • content-encoding: gzip
  • content-type: application/json
  • date: Sun, 27 Feb 2022 04:43:16 GMT
  • etag: "10f2-zWjggrplfqo/Q28tqHsMexHhykU"
  • expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
  • server: cloudflare
  • vary: Accept-Encoding

What I've tried and attempted:

The below is the code I'm currently using:

function getData() {
$.ajax({
    url: `https://nftrade.com/_next/data/_Mat1YwGAWWtzBCNmnbbI/assets/avalanche/0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4/2493.json?chainName=avalanche&contractAddress=0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4&tokenID=2493`,
    type: 'GET',
    crossDomain: true,
    dataType: "jsonp",
    success: function (data) {
    console.log(JSON.stringify(data));
    },
    error: function (data) {
        console.log(JSON.stringify(data));
    }
  })
 }

I've also used this ajax code but no luck:

function getData() {
var url = "https://nftrade.com/_next/data/_Mat1YwGAWWtzBCNmnbbI/assets/avalanche/0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4/2493.json?chainName=avalanche&contractAddress=0x2cca3a1a45c1b1036d7194cd15a981b8c2f9dee4&tokenID=2493";
var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.setRequestHeader("Accept", "*/*");

xhr.onreadystatechange = function () {
 if (xhr.readyState === 4) {
    console.log(xhr.status);
    console.log(xhr.responseText);
 }};

 xhr.send();
}

I used reqbin's code to send an ajax request, which was successful. I'm starting to think it might be an issue with most browsers.

https://reqbin.com/req/nfilsyk5/get-request-example

Where am I going wrong? Can someone please shed some light? Thanks in advance.

8
  • I believe for JSONP to work, the response mimetype needs to be applicaction/javascript not application/json - also, why are you setting a response header ('access-control-allow-origin':'*') in the request? Also, content type makes no sense in a GET request - JSONP isn't a way to circumvent CORS when trying to get JSON - the server MUST recognise a request for JSONP and send the response in the correct JSONP format Commented Feb 27, 2022 at 4:52
  • HI there @Bravo. I have already set my contentType to be application/javascript. Is there something else I'm missing? Commented Feb 27, 2022 at 4:54
  • contentType for a get request make no sense - contentType is the type of content you are sending ... a) a GET doesn't send content, b) you aren't sending javascript (or anything) since it's a GET - understand that the server needs to send JSONP, not JSON, if you expect JSONP ... but the server is sending plain ol' JSON Commented Feb 27, 2022 at 4:57
  • solution ... make the request (for JSON, not JSONP) via your server - server code doesn't get blocked by CORS - which is probably what you're trying to bypass by using JSONP, am I correct? Commented Feb 27, 2022 at 5:00
  • Thanks for your response. I'm making the request through my client side code i.e. javascript. I've removed contentType, along with header. But that has not worked for me. Where am I going wrong? Commented Feb 27, 2022 at 5:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.