Welcome to RP's venture...Here you can find some of the relative topics like ASP.Net, C#.Net,VB.Net, SQL Server, AJAX, Javascripts, Sharepoint, WPF, WCF, Silverlight, MVC, General knowledge, Jokes, Fun, Technical, Non-Technical etc.
0

Javascript Simple AJAX call

Posted by Rajendra Prasad Panchati on Tuesday, February 16, 2010 in
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);
}
}

|

0 Comments

About Me