AJAX,为什么readyState一直是0?

玫_瑰骑_士 2014-05-20 05:27:44
Send方法:


function AjaxRequest()
{
//......
}

// Send an Ajax request to the server
AjaxRequest.prototype.send = function(type, url, handler, postDataType, postData)
{
if (this.request != null)
{
// Kill the previous request
this.request.abort();

// Tack on a dummy parameter to override browser caching
url += "?dummy=" + new Date().getTime();

try
{
this.request.onreadystatechange = handler;
this.request.open(type, url, true); // always asynchronous (true)

if (type.toLowerCase() == "get")
{
// Send a GET request; no data involved
this.request.send(null);
}
else
{
// Send a POST request; the last argument is data
this.request.setRequestHeader("Content-Type", postDataType);
this.request.send(postData);
}
}
catch(e)
{
alert("Ajax error communicating with the server.\n" + "Details: " + e);
}
}
}


按下按钮触发:

document.getElementById("PcButton").onclick = function()
{
//1.最后的检测
var isQualified = false;

//检测过程
isQualified = validate();

//2.输送数据
if(isQualified == true)
{
var account = document.getElementById("Account").value;
var password = document.getElementById("Password").value;

user = new User(account,password);

ajaxReq = new AjaxRequest();
var postData = user.account + "&" + user.password;
ajaxReq.send("POST","Default.aspx",changeHandler,"application/x-www-form-urlencoded;charset=UTF-8",postData);
}
}


为什么会一直是0?还不说send,连open都没触发?
...全文
974 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2014-05-22
  • 打赏
  • 举报
回复
看看 AjaxRequest 的定义
玫_瑰骑_士 2014-05-22
  • 打赏
  • 举报
回复
引用 4 楼 rainsilence 的回复:
changeHandler是怎么写的? 返回0说明没有正确的调用send.
还啥都没写 function changeHandler() {}
rainsilence 2014-05-20
  • 打赏
  • 举报
回复
changeHandler是怎么写的? 返回0说明没有正确的调用send.
rainsilence 2014-05-20
  • 打赏
  • 举报
回复
不管是get还是post再加上 this.request.setRequestHeader("Content-Type", “application/x-www-form-urlencoded;charset=utf-8”);
玫_瑰骑_士 2014-05-20
  • 打赏
  • 举报
回复
引用 1 楼 rainsilence 的回复:
把this.request.abort();去掉试试
也不行= =
rainsilence 2014-05-20
  • 打赏
  • 举报
回复
把this.request.abort();去掉试试

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧