我正在使用,并试图以以下方式使用Jquery.ajax()发送Jquery.ajax:
var data = new FormData();
data.append('some_name', 'some_data');
data.append('a_file', $('input[name=the_file_form_field]').get(0).files[0]));
$.ajax({
url: 'the_destination_url',
data: data,
processData: false,
contentType: false,
type: 'PUT',
dataType: 'json',
success: function(data, textStatus, jqXHR) {
//Processing result here
},
error: function(jqXHR, textStatus, errorThrown) {
//Processing result here
}
});
但是,我尝试了以下场景:
我遗漏了什么吗?
应用程序要求它使用PUT请求,因此POST请求是不可能的。
发布于 2015-09-01 12:19:47
我使用人们发布在:https://bugs.php.net/bug.php?id=26004中的评论来解决这个问题
显然,每当超过post_max_size
指令时,PHP都会默默地丢弃所有传入的POST数据。
除了post_max_size
之外,检查upload_max_filesize
指令也是明智的。
发布于 2015-08-25 12:54:16
只需尝试将数据作为对象发送。例如:
data: {'formData' : data},
您的Ajax请求应该看起来像
$.ajax({
url: 'the_destination_url',
data: {'formData' : data},
processData: false,
contentType: false,
type: 'PUT',
dataType: 'json',
success: function(data, textStatus, jqXHR) {
//Processing result here
},
error: function(jqXHR, textStatus, errorThrown) {
//Processing result here
}
});
发布于 2019-09-14 11:24:53
在PHP中从Ajax JQuery中发送数据的最佳方法是:
在JavaScript中像这样发送数据:
其中mydata为{k1:"val1“,"k2”:"val2“,}
$.ajax({
url: "data.php",
contentType : "json",
data : mydata,
method:"PUT",
success: function (data) {
console.log(data);
},
error: function (err) {
console.log(err);
},
complete:function (e) {
console.log(e);
}
});
获取data.php文件中的数据的方法是:
parse_str(file_get_contents("php://input"),$putVars);
var_dump( $putVars ); // input from your form
https://stackoverflow.com/questions/32203693
复制相似问题