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:
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.
applicaction/javascriptnotapplication/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