[英]XHR failed loading: POST
所以我试图用ajax发布,但它不会通过。
这是我的javascript
$.ajax({
type: 'POST',
contentType: "",
url: 'some url',
data: order,
dataType: 'json',
success: function() {
Materialize.toast('Order added successfully', 4000, 'android-success');
console.log('order posted');
},
error: function() {
Materialize.toast('Something went wrong', 4000, 'android-error');
}
}); // $.ajax post
我没有收到错误,也没有从ajax获得成功。 但是我收到了上面列出的Chrome控制台错误, XHR failed loading: POST
我尝试将内容类型和数据类型设置为无效。 我的猜测是,问题出在对象格式之类的东西上。
可能有用的信息-这是我的代码的基本概述。
这是失败日志下的信息
send @ jquery-3.1.0.js:9392
ajax @ jquery-3.1.0.js:8999
(anonymous function) @ ajax.js:20
mightThrow @ jquery-3.1.0.js:3508
process @ jquery-3.1.0.js:3576
在这个问题上的任何帮助都表示赞赏。
我知道了。 问题在于页面重新加载。 因此,在发布请求可以通过网页之前,将重新加载,这不会导致任何错误,而只会导致日志失败。 gh,这样的菜鸟错误。
我知道老问题,但如果它出现在Google搜索中,则仍然有意义。
加载窗口时,为for添加一个事件侦听器,并阻止默认操作。
<script>
window.addEventListener("load", function () {
//not jquery!
// Access the form element...
var form = document.getElementById("myFormId");
// ...and take over its submit event.
form.addEventListener("submit", function (event) {
event.preventDefault(); // prevent form submission and reloading the page.
//your code to validate or do what you need with the form.
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.