无法从Msxml2.XMLHTTP ajax调用中读取参数

时间:2012-01-23 03:30:52

标签: c# asp.net

使用Msxml2.XMLHTTP ajax调用时,我无法在PageHandler中读取参数。

function InvokeHandler() {
      InitXmlHttp();
      xmlhttp.onreadystatechange = XMLHttpRequestCompleted;
      xmlhttp.open("GET", "BookmarkletHandler.ashx?target=ww1", true);
      xmlhttp.send();
  }

我甚至尝试过:

function InvokeHandler() {
      InitXmlHttp();
      xmlhttp.onreadystatechange = XMLHttpRequestCompleted;
      xmlhttp.open("GET", "BookmarkletHandler.ashx", true);
      xmlhttp.send("target=ww1");
  }


function InvokeHandler() {
      InitXmlHttp();
      xmlhttp.onreadystatechange = XMLHttpRequestCompleted;
      xmlhttp.open("POST", "BookmarkletHandler.ashx", true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
      xmlhttp.send("target=ww1");
  }

这里我试图读取HTTPHandler:

public void ProcessRequest(HttpContext context)
{
   String param = context.Request.QueryString["target"]; --> this gives null
}

有人可以帮忙吗?

感谢。

1 个答案:

答案 0 :(得分:1)

我认为代码是有效的:     函数send()     {       var xmlhttp;       if(window.XMLHttpRequest){//代码适用于IE7 +,Firefox,Chrome,Opera,Safari           xmlhttp = new XMLHttpRequest();       }       else {//代码为IE6,IE5           xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);       }

  xmlhttp.open("POST", "about.aspx", true);
  //must have
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

  xmlhttp.send("fname=1");
  }
ProcessRequest方法中的

:     var res2 = context.Request.Form;