admin管理员组文章数量:1325756
I have this Ajax to send multiple images:
$('#btn').on("click", function () {
var formData = new FormData($("#form1")[0]);
var path = "php/upload/adm_prodpictures.php";
$.ajax({
url: path,
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (stuff) {
$("#resp").html(stuff);
}
});
});
});
I have to process this images in the php-side and insert them in a mysql db. So to insert in the proper way, I have to send a javascript variable. How can I append this variable to the 'bundle' that is sent?
I have this Ajax to send multiple images:
$('#btn').on("click", function () {
var formData = new FormData($("#form1")[0]);
var path = "php/upload/adm_prodpictures.php";
$.ajax({
url: path,
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (stuff) {
$("#resp").html(stuff);
}
});
});
});
I have to process this images in the php-side and insert them in a mysql db. So to insert in the proper way, I have to send a javascript variable. How can I append this variable to the 'bundle' that is sent?
Share Improve this question asked Feb 20, 2016 at 6:09 Pablo De LucaPablo De Luca 8233 gold badges16 silver badges31 bronze badges2 Answers
Reset to default 4To append param just use append()
method:
formData.append("param", "value");
Solved. I add:
formData.append('ipid',id);
So finally my ajax is:
$('#btn').on("click", function () {
var formData = new FormData($("#form1")[0]);
formData.append('ipid',id); //id is the variable that has the data that I need
var path = "php/upload/adm_prodpictures.php";
$.ajax({
url: path,
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (stuff) {
$("#resp").html(stuff);
}
});
});
});
And in the php-side I catch it:
$pid = ($_POST['ipid']);
本文标签: javascriptSend FormDatajs variable by AjaxStack Overflow
版权声明:本文标题:javascript - Send FormData + js variable by Ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742191661a2430329.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论