I'm trying to handle a JSONP Callback, I have the following JavaScript
var URL = "http://localhost:8000/returndata?s=testjsonp";
function alertResponse(data, status) {
alert("data: " + data + ", status: " + status);
}
$.ajax({
url: URL,
dataType: 'jsonp',
jsonpCallback: "alertResponse",
complete: alertResponse
});
When a response to the server is made it returns the following JSON: Note the double quotes.
"alertResponse({'status':'OK'})"
I'm not sure how I can handle this with my javascript.
Can someone help me here.
Thanks
It returns JSONP response treated as string and encoded using JSON.
In other words, the answer from the server is incorrect.
Instead of:
"alertResponse({'status':'OK'})"
it should be:
alertResponse({'status':'OK'})
The point of JSONP is to include it using <script>
tag, so the returned response must be correct JavaScript, calling some callback function (usually specified by one of the GET params during calling remote server) that is supposed to process retrieved data.