gpt4 book ai didi

jquery - 为什么Jquery post不发送数据?

转载 作者:行者123 更新时间:2023-12-01 07:56:28 25 4
gpt4 key购买 nike

嗯,这是一个非常奇怪的问题。我正在形成对象,然后将其发送到服务器,但数据没有到来。(至少 jsp getParameter 返回 null)。

  var _formData = {
"u_id": user.userId,
"f_id": user.filialId,
"photo_id": photo_id
};

jQuery.ajax({
url: 'rep/product_photo/product_photo_delete.jsp',
cache: false,
async: false,
data: _formData,
type: 'POST',
success: function(data){
running = false;
},
error: function(xhr) {
running = false;
}
});

并且在服务器端product_photo_delete.jsp没有获取参数?但是,如果我将其作为 GET 发送,那么一切都可以。 (我已经做过很多次这样的事情,所有这些都有效,但这真的很奇怪)。

  String filialId = request.getParameter("f_id");
String userId = request.getParameter("u_id");
String photoId = request.getParameter("photo_id");

它们都返回 null!

此外,请求负载为:

u_id=0&f_id=0&photo_id=43

最佳答案

看起来您有一个全局 ajax 设置,它将 contentType 设置为 application/json 或其他内容。

问题:Demo - 查看网络选项卡以监控请求格式,而不是 FormData,请求值作为请求负载发送

enter image description here

要将数据作为请求参数发送,请将其设置为application/x-www-form-urlencoded; charset=UTF-8 就像

jQuery.ajax({
url: 'rep/product_photo/product_photo_delete.jsp',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
//processData:true,
cache: false,
async: false,
data: _formData,
type: 'POST',
success: function (data) {
running = false;
},
error: function (xhr) {
running = false;
}
});

演示:Fiddle enter image description here

关于jquery - 为什么Jquery post不发送数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23888036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com