I am trying to get values from a third party webservice. When I resolve the API link directly in my browser, it works fine and shows result (in json format)
API Link: http://outlineme.com/test/index.php
Result: {"result":true,"time":"2013-04-28 08:19:10"}
But when I run the same code using jQuery AJAX (with JSONP datatype) it does not show up anything. My code is below:
It’s a cross domain thing. The following is from Stack Overflow
Say you’re on domain abc.com, and you want to make a request to domain xyz.com. To do so, you need to cross domain boundaries, a no-no in most of browserland.
The one item that bypasses this limitation is <script> tags. When you use a script tag, the domain limitation is ignored, but under normal circumstances, you can’t really DO anything with the results, the script just gets evaluated.
Enter JSONP. When you make your request to a server that is JSONP enabled, you pass a special parameter that tells the server a little bit about your page. That way, the server is able to nicely wrap up its response in a way that your page can handle.
For example, say the server expects a parameter called “callback” to enable its JSONP capabilities. Then your request would look like:
I mean, when getting the same request with PHP, there is no concept of JSONP, all you can do is run a CURL request to the API server and store the output in a variable say $response and then json decode the response:
Yeah, as I mentioned, cross-domain requests in JS ar a no-no. cURL is a different ball game and AFAIK isn’t subject to the same restrictions.
It’s like comparing apples and pears.
As script tags bypass the cross-domain limitation, I would just dynamically create one of these and embed it in your page, then run a call-back function to do whatever it is you need with the JSON. Here’s an updated fiddle
AFAIK, yes.
In my above example, try swapping out: