Method : Post
function AjaxCalltoPostData(datastring) { var xmlhttp; var responsestring; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { responsestring = xmlhttp.responseText; } } var data = "content=" + datastring; xmlhttp.open("POST", "TempPage.aspx", true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.send(data); }
On Page Load of TempPage.aspx Get Data using :
string content = Request["content"];
*******************************************************************************
Method : Get
function AjaxCallUsingGetMethod() { var xmlhttp; var responsestring; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { responsestring= xmlhttp.responseText; } } xmlhttp.open("GET", "TempPage.aspx?func=getdata&source=" + $('#txtsource').val() + "&dest=" + $('#txtdestination').val() + "&fdate=" + $('#datetoday').val() + "", true); xmlhttp.send(); }
On Page Load of TempPage.aspx Get Data using :
string funname = Convert.ToString(Request.QueryString["func"]); if ((funname + "").Trim().ToLower() == "getdata") { string src = Convert.ToString(Request.QueryString["source"]); string dest = Convert.ToString(Request.QueryString["dest"]); DateTime fdate = Convert.ToDateTime(Request.QueryString["fdate"]); string xmlres = GetDataFromASPFunc(src, dest, fdate); Response.Write(xmlres); }