【发布时间】:2011-05-15 00:40:22
【问题描述】:
我无法访问 SayHello.ashx,我收到了这个 javascript 错误:
httpReq.open 不是函数。
但是当我使用 aspx 页面回答 xmlhttprequest 时,代码可以正常工作:
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;
}
【问题讨论】:
标签: javascript xmlhttprequest ashx