I am using jquery to do ajax calls:
// omitting the code for the options properties
var options = {
type: Type,
url: Url,
data: '{aString:"abc"}',
contentType: ContentType,
dataType: dataType,
//processdata: ProcessData,
success: function (msg) {
ServiceSucceeded(msg);
},
error: ServiceFailed
};
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
}
$.ajax(options).done(function () {
alert("success: " + msg);
});
This call works in that the url defined in options is called. The endpoint is a wcf service which I host so I have verified it’s called as expected.
I monitor the call with fiddler, and I see nothing wrong with the request or the response. The http response code is 200 OK.
But the function in done is not called. Instead ServiceFailed is run. Why is this? Why is done() not called, and why does jquery consi
We can only guess on the basis of what you’ve posted.
You’re specifying a
dataTypeto jQuery (but haven’t told us what that data type is), which means you’re (potentially) telling it to transform the result. For instance, if yourdataTypevariable is “json”, jQuery will try to convert the result to JSON; if it’s “xml”, jQuery will try to convert the result to XML.If you’re watching the call occur and seeing a 200 response with content, that suggests to me that it’s the data conversion that fails.
You can readily find out more about why an error occurs. The
errorfunction is called with this signature:…so you can put a breakpoint inside it and inspect
textStatus(which should be 200 based on your monitoring of the result, but if it isn’t that’s useful information) and theerrorThrown, which would probably give you some idea what went wrong.