为什么JQuery ajax POST脚本会抛出错误400? [英] Why does the JQuery ajax POST script throw error 400?
本文介绍了为什么JQuery ajax POST脚本会抛出错误400?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 $。ajax({})
更新div MSGS,但目前正在抛出错误400:错误请求
。
I have $.ajax({})
that is ment to update the div MSGS, but is currently just throwing Error 400: Bad Request
.
我也有一些烧瓶代码,请参阅repl。
I Also have some flask code too, see the repl.
代码:
function ajax_(){
console.log("Running func")
$.ajax({
url: "/chat",
contentType: "application/json;", dataType: "json",
data: JSON.stringify("SOMETHING"),
method: 'POST',
type: "POST",
success: function(){
console.log("Success");
document.getElementById("msgs").innerHTML = $("#msgs").html();
}, error: function(){
console.log("Error!")
}
});
};
setInterval(function(){ ajax_(); }, 1000);
Repl: https://repl.it/@aceharvey/hy-dev
编辑:这两个问题都没有标记为重复有工作答案。
Neither of the questions that have been marked as duplicate have working answers.
推荐答案
我确信你需要发送一些数据与请求。
I am sure you need to send some data with the request.
function ajax_(){
console.log("Running func")
$.ajax({
url: "/chat",
data: "SOMETHING" <----
method: 'POST',
type: "POST",
success: function(){
console.log("Success");
document.getElementById("msgs").innerHTML = $("#msgs").html();
}, error: function(){
console.log("Error!")
}
});
};
setInterval(function(){ ajax_(); }, 1000);
这篇关于为什么JQuery ajax POST脚本会抛出错误400?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文