XMLHTTPRequest.send() in not working firefox
XMLHTTPRequest.send() in not working firefox
以下一段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
以及提交表单数据的其他方式https://developer.mozilla.org/en-US/docs/Web/Guide/Using_FormData_Objects
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working