2012-09-21 66 views
2

我从javascript代码中调用通用处理程序(ashx),如下所示;如何将参数从JavaScript传递给通用处理程序?

var xmlHttpReq = createXMLHttpRequest(); 
      xmlHttpReq.open("GET", "hndlrCars.ashx, false); 
      xmlHttpReq.send(null); 
      xmlText = xmlHttpReq.responseText; 

但我不得不从的.aspx到通用处理器的“的ProcessRequest” method.How我能做到这一点通过参数(下拉的SelectedValue)?

回答

3

你可以将它作为查询字符串参数:

var value = ... 
xmlHttpReq.open('GET', 'hndlrCars.ashx?value=' + encodeURIComponent(value), false); 

而且处理程序中从请求检索:

public void ProcessRequest(HttpContext context) 
{ 
    string value = context.Request["value"]; 
    ... 
} 
相关问题