2

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?

2 Answers 2

4

To append param just use append() method:

formData.append("param", "value");
Sign up to request clarification or add additional context in comments.

1 Comment

I've just found the solution but thanks anyway. This is exactly what I did :)
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.