0
Javascript Simple AJAX call
Posted by Rajendra Prasad Panchati
on
Tuesday, February 16, 2010
in
Javascript
var xmlHttp;
function RequestAjaxCall()
{
if (window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
else if (window.ActiveXObject)
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.onreadystatechange = ResponseAJAXCall;
var str ="Param="+ConditionParam;//Condition to do an action
xmlHttp.open('POST', "Default.aspx?"+str, true);
xmlHttp.send("");
}
In between, you need to to grab the condition in your default.aspx page and do required operations and write as below in your Default.aspx.cs
Response.Write("Your Response");
Again write the response grab function in your javascript file as below. Function name should match with the request function on ready state change function name.
function ResponseAJAXCall()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
{
var respo = xmlHttp.responseText;
alert(respo);
}
}
function RequestAjaxCall()
{
if (window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
else if (window.ActiveXObject)
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.onreadystatechange = ResponseAJAXCall;
var str ="Param="+ConditionParam;//Condition to do an action
xmlHttp.open('POST', "Default.aspx?"+str, true);
xmlHttp.send("");
}
In between, you need to to grab the condition in your default.aspx page and do required operations and write as below in your Default.aspx.cs
Response.Write("Your Response");
Again write the response grab function in your javascript file as below. Function name should match with the request function on ready state change function name.
function ResponseAJAXCall()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
{
var respo = xmlHttp.responseText;
alert(respo);
}
}
More
Less