Javascript firefox中的XMLHTTPRequest.send()不工作

Javascript firefox中的XMLHTTPRequest.send()不工作,javascript,Javascript,下面的js代码不仅适用于firefox,而且适用于chrome和IE。请任何人提供帮助 我试图提交两个表单,只需点击一个按钮 function abc(url){ var form = document.getElementById("sample"); var xhr = new XMLHttpRequest(); xhr.open("POST", url, true); xhr.setRequestHeader("Content-type", "application/x-www-form-

下面的js代码不仅适用于firefox,而且适用于chrome和IE。请任何人提供帮助

我试图提交两个表单,只需点击一个按钮

function abc(url){
var form = document.getElementById("sample");
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("actionCode=2");

var form1 = document.getElementById("sample1");
form1.submit();
}
奇怪的是,在第xhr.send()行放置一个使用firebug的调试器时,它就工作了,只要我从firebug中删除调试器,xhr.send就不会执行

非常感谢您的建议。
谢谢

这是异步请求,您需要检查请求的状态

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
 if (xhr.readyState == 4 && xhr.status == 200) {
   var form1 = document.getElementById("sample1");
   form1.submit();
 }
}
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type",  "application/x-www-form-urlencoded");
xhr.send("actionCode=2");

or this may help

xhr.open("POST", url, false); - it will make the request synchronous. 
Then you will not required to move submit or listen to events 
以及提交表单数据的其他方式

到底什么不起作用?发送请求或提交表单?为什么需要监听响应才能使请求正常工作?@Felix Kling这是不必要的,但您在发送请求后才提交表单,此请求是异步的,这意味着函数将不会叠加在xhr上。发送直到响应,并将继续提交,这将提交表格,可能会减少您的请求。如果您将移动,请提交到警报位置(xhr.responseText);它将在收到表格后提交表格response@FelixKling或者您可以通过将true替换为false来执行请求同步xhr.open(类型、url、false);