我允许自己张贴,因为我不能发送我的邮件请求,其中包含一个数据文件和两个职位
验证码:
$('#image--1').change(function (e) {
e.preventDefault();
var img = new FormData();
img.append( 'media', $('#image--1')[0].files[0]);
var idarticle = $('#article').val();
uploadphoto(img,1,idarticle)
});
function uploadphoto(media,numphoto,idarticle)
{
console.log('num : ' + numphoto);
console.log('idarticle : ' + idarticle);
$.ajax({
type: "POST",
url: "ajax/change-photo.php",
processData: false,
contentType: false,
data: {
media:media,
numphoto:numphoto,
idarticle:idarticle
},
dataType: "JSON"
}).done(function (ret){
console.log(ret.responseText)
}).fail(function(ret){
console.log(ret.responseText)
})
}
字符串
返回控制台:
<b>Warning</b>: Undefined array key "idarticle" in <b>/srv/web/gestionnel/public/ajax/change-photo.php</b> on line <b>7</b><br />
NULL
<br />
<b>Warning</b>: Undefined variable $id_article in <b>/srv/web/gestionnel/public/ajax/change-photo.php</b> on line <b>13</b><br />
型
我想使用Ajax正确发送数据
1条答案
按热度按时间rwqw0loc1#
你不能把
media
放在data:
对象里面,它必须是整个值。你应该给它添加其他参数。字符串