简体   繁体   中英

How to parse response from this jsonp call (jquery)

I am trying to make a JSON call to an external site (which I have no control over) in order to retrieve a pricelist. It's a simple call:

$.ajax({
url: 'http://www.external-site.com',
type: 'GET',
contentType: 'application/json',
dataType: 'jsonp',
data: {SelectedObjectId:"742",DeliveryOptionId:"2",CountryId:"4",SelectedExtensionId:"-1"},
success: function(response) { console.log('succes: ' + response); },
error: function(response) { console.log('error: ' + response); }
});

When I look in the Chrome developer tools, I see a response is returned with all the information I expect. However the 'succes' status is not returned, instead the 'error' function is executed and when I log the response, I end up with an object that does not seem to be the same as the json response I see in the developer tools. How do I retrieve and work with the response that shows up in developer tools? I'm inexperienced with ajax calls and did a lot of searching and trying different things but none have worked in this particular case.

Edit: I removed the JSfiddle and the link to the external site in order to prevent potential strain on their server.

Thanks to Arun P Johny's comments above I was able to solve this issue by making the ajax request to a simple proxy.php on my server, which in turn fetches the external site and returns the data that I need.

I used this tutorial on how to set it up: http://blog.edwards-research.com/2012/10/cross-domain-ajax-a-simple-workaround/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM