你如何用JavaScript调用ASHX? [英] How do you call an ASHX from JavaScript?
本文介绍了你如何用JavaScript调用ASHX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想调用ASHX文件并从JavaScript传递一些查询字符串变量,并将返回字符串转换为JavaScript中的字符串。我该怎么做?
I want to call an ASHX file and pass some query string variables from JavaScript and get the return string into a string in the JavaScript. How would I do this?
ASHX文件已编码为response.write一个基于查询字符串的字符串。
The ASHX file is already coded to response.write a string based on whatever the query strings are.
推荐答案
这样的东西?:
function createXMLHttpRequest() {
try { return new XMLHttpRequest(); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
alert("XMLHttpRequest not supported");
return null;
}
var xmlHttpReq= createXMLHttpRequest();
xmlHttpReq.open("GET", "your.ashx?v1=1&v2=2&etc", false);
xmlHttpReq.send(null);
var yourJSString = xmlHttpReq.responseText;
这篇关于你如何用JavaScript调用ASHX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文