Here's what I do: I can't take all the merits, because I found examples from the example.
var varType;
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
function CallService()
{
$.ajax({
type : varType,
url : varUrl,
data : varData,
contentType : varContentType,
dataType : varDataType,
processdata : varProcessData,
success : function(msg) {
ServiceSucceeded(msg);
},
error: ServiceFailed
});
}
Then we have a function of success
function ServiceSucceeded(result) {
....
}
Then the function for failures
function ServiceFailed(result) {
...
}
Then, finally, an example of ajax function call:
function GetWCFJSON() {
varType = "POST";
varUrl = "service/WCFService.svc/GetMyData";
varData = '{"States": "' + $('#ddlStates').val() + '"}';
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = true;
CallService();
}
source
share