I'm executing the following AJAX call to another domain.
$.ajax({
url: "http://.../MyService.svc/Ping",
dataType: 'jsonp',
jsonp: 'callback',
processData: false,
jsonpCallback: 'jsonCallback',
success: function (a, b, c) { notify("Wheee..."); },
error: function (a, b, c) { notify("Buuu... " + a + "-" + b + "-" + c); }
});
I get the connection and the status is 200 OK. However, I get the call to error method that notifies me that parsererror and jsonCallback was not called. The URL I see being called looks like this.
[12:29:55.807] GET =1371724195683">http://.../MyService.svc/Ping?callback=jsonCallback&=1371724195683 [HTTP/1.1 200 OK 1912ms]
The service is configured to serve JSON format. If I manually enter the call in the URL line of my browser, the response on the screen says this.
"jsonCallback(pong @ 10:38:46 20-Jun-2013)"
I'm out of ideas on what I'm missing. (It's probably something straight-forward but I've got agitated and my annoyance hinders me from realizing what that might be.)
EDIT:
After being pointed out that the validity of the returned JSON object is mandatory, I tested a few different outputs via the browser's URL line, as listed below. None of these seemed to change the parsererror problem though when making the call from JS. What more can I be doing wrong?
"{result: \"pong at 12:42:06 20-Jun-2013\"}"
"jsonCallback('{result: \"pong at 12:49:54 20-Jun-2013\"}')"
EDIT:
The parser of @.ajax is actually very forgiving. However, on needs to activate the cross domain scripting access in web.config as shown below. ANd make sure you do that on the correct endpoint.
<webHttpBinding>
<binding name="UrlHttpBindingJsonP"
crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
See this article.