Communication between js client and asp.net server
I write web site in VS 2008. I use extjs for make side with gridView and button. Now I want to send request to server. I add event to click on button:
function getData()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
} else
{
xmlhttp = new ActiveXObject("Mic开发者_高级运维rosoft.XMLHTTP");
}
xmlhttp.open("GET", "Default.aspx", true);
xmlhttp.setRequestHeader("data", "true");
xmlhttp.send();
}
And my question is how can I receive this request on server? I found in the Internet that I should to do it like this:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Headers["data"] != null)
{
// do something
}
}
but it doesn't work. I don't understand it, if I use JS page doesn't reload, so why I must check it in method page_load?
Client side:
For sending GET-request use :
xmlhttp.open("GET", "Default.aspx?data=true");
Server side:
Use HttpRequest.QueryString for getting params.
精彩评论