这是提交的js代码:
XMLHttpReq.open("post","/BlogPlatform/saveArticle.do", true);
XMLHttpReq.onreadystatechange=processSaveResponse;
XMLHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
XMLHttpReq.send(url); // 发送请求
XMLHttpReq.onreadystatechange=processSaveResponse;
XMLHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
XMLHttpReq.send(url); // 发送请求
在processSaveResponse响应方法中,readyState的状态到1就停滞不前了,但action里面处理数据的代码还是执行正确
百思不得其解,后来经过尝试,原来是我提交动作的按钮放到表单中了
原来是
<form name="logonForm" action="#">
<input type="name"></input>
<input type="button" onclick="saveRequest()"/>
</form>
改成:
<form name="logonForm" action="#">
<input type="text" name="entrytitle"></input>
</form>
<input type="button" onclick="saveRequest()"/>
就一切正常了,我想可能是因为ajax异步提交,不能再像原来一样把提交按钮放在form中
其实,ajax根本就没有用form,再js中,只是抽取form中的文本域的数值
比如:
var title = document.logonForm.entrytitle.value;
本文介绍了一种在使用Ajax进行异步提交时遇到的问题及解决方案。作者发现将提交按钮置于表单内会导致Ajax请求的readyState停留在1,通过将按钮移出表单,成功解决了这一问题。


被折叠的 条评论
为什么被折叠?



