Share
Improve this question
edited Nov 13, 2012 at 14:57Jayaram
asked Dec 20, 2011 at 21:08
JayaramJayaram83911 gold badge1515 silver badges2424 bronze badges7
3Start Googling for "cross domain ajax."
– Matt Ball
CommentedDec 20, 2011 at 21:09
1@RoyiNamir Still considered cross-domain... "However, the mon moniker for these requests, cross-domain, tends to be misleading. While a request from one domain to another is obviously cross-origin, browsers are much more picky than that. For example, a request from foo.domain. to bar.domain. is just as much cross-origin request as one to abc.. That’s not quite as intuitive as the traditional cross-domain scenario, but requires the same consideration." - encosia./…
– Alex
CommentedDec 20, 2011 at 21:11
Yep, by default browsers doesn't allow javascript to perform requests to different domains / protocols.. of course, there are several workarounds to this
– redShadow
CommentedDec 20, 2011 at 21:12
Also, question title should be updated to something like "How to make cross-domain requests using jquery"...
– redShadow
CommentedDec 20, 2011 at 21:14
@RoyiNamir np - Jayaram feel free to follow the link I've provided, in my ment above, to gain more insight on the topic...
– Alex
CommentedDec 20, 2011 at 21:17
|
Show 2 more ments
1 Answer
1
Reset to default
7
there are a couple of problems. First, you need to add &callback=? to the end of the querystring to allow the crossdomain.
You will then get an Uncaught SyntaxError: Unexpected token : error. This is because you are expecting json data, but the headers on the server are sending text/html - not application/json. Take a look at the console when you run this fiddle, you'll see the errors.
Therefore, you can't get the data from cross domain because you have to be using jsonp - which requires the header to be sent correctly.
If this is your api, then you just need to send the correct header, otherwise, you need to get with the developers there and ask them to fix it.
Alternatively
If neither of those above options work, you could always create a proxy script that would get the contents of the json feed for you and echo it out. Here's one in PHP: