I just checked the test with the below. It does not throw an error if HTTP 200 is passed back. The var 'result contains everything you expect. Remove the data type if you do not want to use JSON.
function ajaxRequest (request, url) {
$ .ajax ({
type: "POST",
contentType: "application / json; charset = utf-8",
url: url,
data: data,
dataType: "json",
cache: false,
async: false,
success: function (result) {
// this only happens on success
},
error: function (msg, XMLStatus, Err) {
ajaxError (msg, XMLStatus, Err); // Call generic error message
}
});
}
I use this as a general success / error method for interacting with a web service.
/ * Data must be prepared in a standard JSON format, either using $ .toJSON () for objects, or stringbuilding for individual parameters * /
/ * General AJAX request handler * /
/ * serviceName is the full path of the service ie. "fullpath / services / service.asmx / method /" * /
function ajaxRequest (data, serviceName, callbackFunction, async) {
$ .ajax ({
type: "POST",
contentType: "application / json; charset = utf-8",
url: serviceName,
data: data,
dataType: "json",
cache: false,
async: async,
success: function (response) {
callbackFunction.Success (response);
},
error: function (msg, XMLStatus, Err) {
callbackFunction.Error (msg, XMLStatus, Err);
}
});
}
/ * Sample use * /
function getStuff (a, b, c) {
// Sample method signiture: getStuff (string a, string b, string c)
var data = "{"
data + = "'a'" + ": '" + a + "'"
data + = ", 'b'" + ": '" + b + "'"
data + = ", 'c'" + ": '" + c + "'"
data + = "}";
someParameterImayWantToUseInTheCallBack = "This was the test click button";
serviceName = "/taccapps/samples/servicesample.asmx/getStuff/";
ajaxRequest (data, serviceName, new sampleCallback (someParameterImayWantToUseInTheCallBack), true);
}
/ * Sample callback * /
function sampleCallback (someParameterImayWantToUseInTheCallBack) {
// someParameterImayWantToUseInTheCallBack is available to both the success and fail methods
this.Success (response) {
// "response" represents the JSON response from the server. If it is a list / array it can be dotted into using the index.
for (item in response) {
alert (response [item] .a);
alert (response [item] .b);
alert (response [item] .c);
}
};
this.Error (msg, XMLStatus, err) {
// Standard HTTP error codes are found in the above
};
}