jquery - JSON or JSONP query to retrieve data -
There are a few questions about this kind of issue, such as:
I have been given the API call to use the process (I believe it is based on the rest API) is retrieving prices from a server, it looks like this:
http://stage.xxxxxxxxx.co.uk/Search/?q=london&srid=3857&format=json&api_key=Xxxxxxxxxxxxxxxxxxxxxxxx For clear reasons Specially for the key have to use xxxxx
Submitting it to a web browser like IE returns that looks like JSON object, looks like this:
{"features": [{"id": 2728329, "name": "London", "London", "City": "City": "London", "Address": "London", "address_2": Null, "DISPLAY_TEXT": "London London", "Geometry": {"type" : "Point", "Coordinate": [-16,004.68 9 675, 67,08,355.9 67 9 61]}, "Longitude": -16004.68 9, 675330877, "lat": 67,08,355.9 6,7 9, 60811}]} Trouble I use the JSON object (or here I am trying to retrieve this object as a string).
I quickly learned that XMLHttpRequest does not work because of using 'same domain', so I changed JSONP, but I have failed to understand how to use it properly.
For example, I have th.
$ getJSON ("http://stage.xxxxxxxxxxx.co.uk/Search/?q=london&srid=3857&format=json&api_key=xxxxxxxxxxxxxxxxxxxxxxxxx?callback=?", Function (results) {format: "json"}); Where do I go from here to get the JSON object described above?
I quickly found out that XMLHttpRequest because I'm using 'same domain' Turning to JSONP does not work, but I'm unable to use it properly to understand.
You can not use JSONP, unless you endorse the last point you are calling, and you say that you are requesting this. That's because he has to send back a different format (JSONP instead of JSON).
JSON and JSONP are basically different, despite seeing very nearly the same one. JSON response is a text format that defines the data according to the JSON standard (loose document, and more formally anywhere is an RFC); The JSONP response is a function call in a JavaScript object that is executed as a script code.
Here is an example of a simple theoretical JSON query and response:
Request: http://example.com/give-me-deh-stuff?format= Json & amp; id = foo
response:
Request: http://example.com/give-me-deh-stuff?format=jsonp&id=foo
Feedback:
< Pre> callback ({"stuff": {"foo": "bar"}}) .. and one where you do it:
request : http://example.com/give-me-deh-stuff?format=jsonp&callback=_cb12345&id=foo
Answer: _cb12345 ({ "Content": {"foo": "bar"}}
If the endpoint supports JSONP, then jQuery will happily provide the callback function and set the argument on the URL, You need to tell what the logic is called (this is the callback if you do not, which many APIs use and many others do not).
Note that the JSONP version is calling the function ( callback or _cb12345 ), your code (or jQuery) ensures that the name on that global name There is a function with, and after that you add the script to the request URL, and when it comes back it keeps going. How it is avoided by JSONP similar Genesis policy.
Comments
Post a Comment