I am trying to write some JavaScript that calls a Web Service I’ve created. This web service is part of another
function ping() {
$.ajax({
url: "http://myserver/OtherSite/ping?$format=json",
dataType: "jsonp",
type: "GET",
success: ping_Succeeded,
error: ping_Failed
});
}
function ping_Succeeded(result) {
alert("success");
}
function ping_Failed(e1, e2, e3) {
console.log(e1 + "\n" + e2 + "\n" + e3);
}
When I execute this code, I notice in Fiddler that my request to my web service is fine. A 200 is returned. The JSON that I am expecting is there. However, in the JavaScript console, I see an error that says: “Uncaught SyntaxError: Unexpected Token:”.
In looking in the console, I noticed the following: “message: “jQuery18209005181000102311_1352904505837 was not called”.
I don’t understand what I’m doing wrong. Can someone please tell me what is wrong with my code?
Thank you
Looks like you are missing to wrap your JSON into callback call.
Because of
dataType:"jsonp"jquery will send request to an URL like this:So, you must take a name from callback and wrap your response like this (on server):
Or you can try to replace
dataType:"jsonp"withdataType:"json"