Reputation: 113
Currently, I am using the JQuery Ajax command to call a WCF Service called isValidUser. Using chrome to debug, I can see that the WCF Service is sending what appears to be the correct JSON Response back. The success callback method defined in the JQuery is also getting called. However, the alert message is outputting 'Undefined.'
Below is the snippet of the Client script that I used.
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: 'http://localhost:28506/VikingServices.svc/isValidUser/john/doe',
processData: false,
dataType: "jsonp",
jsonpCallback: "callback",
success: callback,
error: ServiceFailed
});
function callback(data) {
alert(data);
}
function ServiceFailed(xhr) {
alert(xhr.responseText);
if (xhr.responseText) {
var err = xhr.responseText;
if (err)
error(err);
else
error({ Message: "Unknown server error." })
}
return;
}
This is the response that I see in the Chrome Developer tools response from the Ajax Request:
{"Name":"Super Admin","Username":"john","id":1}
Upvotes: 1
Views: 640
Reputation: 116
Your datatype is 'jsonp', therefore your response must be a valid jsonp response. Something like
callback({"Name":"Super Admin","Username":"john","id":1});
Should work. There is also a validator: http://json-p.org/validator.html
Upvotes: 2