Tuesday 21 April 2009

How to make call using Ajax/ JQuery

First thing you got to include Jquery library
Second thing:
create some functions inside jqueries ready function like this:
$(document).ready(
function()
{
// if you want to take any action on load
});
Third:
There are few ways to do this call and here are 3 ways of them:

1) This is a get call
$("#DivToDisplayResult).load('pageToBeCalled.cfm',{
Param1: param1value,
Param2: param2value,
Param2: param2value,
Param2: param2value,
……..
},
// following function is required, which is being called after we get the result back
function(responseText, textStatus, XMLHttpRequest){
//alert(responseText);
}
2) $.getJSON('pageToBeCalled.cfm',{UserProfileCode: userProfCode}, function(j){
// here you can put the action and you would get result in “j” variable
// like
$("#divName").html(j);
});
3) Post
$.post(
pageToBeCalled.cfm,
{
Param1: param1value,
Param2: param2value,
Param2: param2value, },
function(j) {
//here you can take action by reading “j” variable
}
);

No comments: