当use.ashx address获得javascript错误时:myxmlhttprequest.open不是函数
我无法访问SayHello.ashx,我遇到以下javascript错误: httpReq.open不是一个函数 但是,当我使用aspx页面回答xmlhttprequest时,代码运行良好:当use.ashx address获得javascript错误时:myxmlhttprequest.open不是函数,javascript,xmlhttprequest,ashx,Javascript,Xmlhttprequest,Ashx,我无法访问SayHello.ashx,我遇到以下javascript错误: httpReq.open不是一个函数 但是,当我使用aspx页面回答xmlhttprequest时,代码运行良好: httpReq.open("POST", "SayHello.aspx"); 问题在哪里?问题可能来自我的.ashx文件吗 function callASHX() { var httpReq=XMLHttpRequest(); var x = document.getE
httpReq.open("POST", "SayHello.aspx");
问题在哪里?问题可能来自我的.ashx文件吗
function callASHX() {
var httpReq=XMLHttpRequest();
var x = document.getElementById('txtName').value;
var sendStr = "user_id=" + x;
httpReq.open("POST", "SayHello.ashx");
httpReq.onreadystatechange = XMLHttpRequestCompleted;
httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpReq.send(sendStr);
}
// initialize XMLHttpRequest object
function XMLHttpRequest() {
var httpReq;
try {
// Opera 8.0+, Firefox, Safari
httpReq = new XMLHttpRequest();
}
catch (e) {
// IEBrowsers
try {
httpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
return false;
}
}
}
return httpReq;
}
您没有分配
XMLHttpRequest()
的返回对象
试试这个:
function callASHX()
{
var httpReq = XMLHttpRequest();
....
if (httpReq) //potentially this is 'false'!
{
httpReq.open("POST", "SayHello.ashx");
....
}
谢谢,但当编译器到达这一行时,我又遇到了同样的错误:httpReq.open(“POST”,“SayHello.ashx”);注意,同样的错误。该页面用于连接到localhost并完成,注意show。我发现Firefox4中的开发者工具栏有错误