There are a lot of questions on SO about this sort of issue, eg:
Basic example of using .ajax() with JSONP?
But I can't seem to get any of them to return a sensible result.
I have been given an API call procedure to use (I believe it is based on the REST API) to retrieve values from a server, it looks like this:
http://stage.xxxxxxxxx.co.uk/Search/?q=london&srid=3857&format=json&api_key=xxxxxxxxxxxxxxxxxxxxxxxx
I've had to use xxxxx for obvious reasons, particularly for the key.
Submitting this to a web browser such as IE returns what appears to be a JSON object, looks like this:
{
"features": [
{
"id": 2728329,
"name": "LONDON",
"city": null,
"county": "LONDON",
"address": "LONDON",
"address_2": null,
"display_text": "LONDON LONDON",
"geometry": {
"type": "Point",
"coordinates": [
-16004.689675,
6708355.967961
]
},
"lon": -16004.689675330877,
"lat": 6708355.967960811
}
]
}
The trouble I'm having is trying to retrieve this object as a JSON object (or even a string) using jQuery.
I quickly discovered that XMLHttpRequest doesn't work because of using the 'same domain' so I turned to JSONP, but I'm failing to understand how to use it properly.
For example, I have this:
$.getJSON("http://stage.xxxxxxxxxxx.co.uk/Search/?q=london&srid=3857&format=json&api_key=xxxxxxxxxxxxxxxxxxxxxxxxx?callback=?", function(result) {
format: "json"
});
Where do I go from here to get the JSON object mentioned above?