// Implementation
makeAjaxCall("/Controller/Action", "GET", { arg1:"value1", arg2:"value2"}, "Error loading data !", "error", function(response) {
ds = response;
});
function makeAjaxCall(url, methodType, jsonData, errorText, errorType, callback) {
$.ajax({
url: url,
method: methodType,
dataType: "json",
contentType: 'application/json; charset=utf-8',
data: jsonData,
async: false,
success: function (result) {
result = result === null ? [] : result;
var p = false;
try {
JSON.parse(result); // try parse json if success .. parse & send data .. else send as it is
p = true;
}
catch (e) { }
p === true ? result = JSON.parse(result) : result = result;
return callback(result);
},
error: function (result) {
window.alert(errorText, errorType, 5000);
return;
}
});
}
Comments
Post a Comment