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']);