Search code examples
javascriptajaxjsonpsame-origin-policy

Can't get any data back using JSONP when making a cross-domain request


I have a website that I need to send a GET request to from my browser and get HTML data back. But the website has a "X-Frame-Option: DENY" and I can't make an Ajax request because of CORS policy. So I tried it with JSONP but it's not returning me any data. It does says 200 OK for connection though. I'm using the latest version of Chrome.

// Not returning HTML back
$.getJSON("https://www.google.com/?callback=?", function(result) {
   console.log(result)
})

// I tried this but also didn't work
$.ajax({
     url: 'https://www.google.com',
     dataType: 'jsonp',
     success: function(result) {
         console.log(result)
     }
})

I'm not sure what is going on here..


Solution

  • JSONP only works if the URL you are calling contains data formatted as JSONP.

    The URL you are using contains HTML not JSONP.

    You cannot read arbitrary data with JSONP. It isn't a magic wand that disables the same-origin policy in browsers.