I've wrote the following function so I don't need to rewrite ajax calls for every event I have.
function ajaxCall(){
var params = new Array();
for(var i = 0; i < arguments.length; i++ ){
params[i] = arguments[i];
}
$.ajax({
url: params[0],
type: params[1],
data: params[2],
dataType : "json",
beforeSend: function(x) {
if(x && x.overrideMimeType){
x.overrideMimeType("application/json;charset=UTF-8");
}
}
});
}
Since ajax is asynchronous I cannot simply return the result from the ajaxCall function when call is successful. How can I create a success call back function? I've tried out this but it's probably wrong. Please help me on since I'm new to jquery & javascript.
ajaxCall("/getItemGroups", "POST" , data).success(function(){
alert("success");
});