Saturday, December 3, 2011

Ajax call using JQuery

Here is a basic version of the method that does ajax call using jquery. This does a synchronous ajax call. Change async parameter to true to make it asynchronous.

function doAjaxCall(url, dataMap){
    var jqxhr =$.ajax({ uri: uri,
    type: "POST",
    data: dataMap,
    cache: false,
    async: false
    })
    .success( function(){})
    .error(function() {})
    .complete(function() {});
    return jqxhr;
}




var data={};
data.inputOne = 1;
data.inputTwo = "test";
url= "testUrl.do" ;

jqxhr = doAjaxCall(url, data);
jqxhr.success(function(html){
 alert("return value is: " + html);
});

jqxhr.error(function(html){
 alert("error occured: " + html);
});

No comments:

Post a Comment