JavaScript Send FormData + js variable by Ajax javascript variable form data,ajax send formdata and variable

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?

Answer:1

To append param just use append() method:

formData.append("param", "value");
Answer:2

I have a string like this: var variable = 'one|two|three|four|five'; This regex /^(\w+)\|/ matches first word (from left side). In other word, $1 returns one. Now I need to get second word from the ...

I have a string like this: var variable = 'one|two|three|four|five'; This regex /^(\w+)\|/ matches first word (from left side). In other word, $1 returns one. Now I need to get second word from the ...

Say I have an array of strings like this: originalArray = ["some value", "another value", "and another"] How would you add to both the beginning and end of each string so it looks like this: ...

Say I have an array of strings like this: originalArray = ["some value", "another value", "and another"] How would you add to both the beginning and end of each string so it looks like this: ...

  1. append values javascript
  2. append values javascript array

I want to run mongod command in node.js using Promises, so that database operations can run only after mongodb process is started. I tried my hands with following, but failed: var Promise = require("...

I want to run mongod command in node.js using Promises, so that database operations can run only after mongodb process is started. I tried my hands with following, but failed: var Promise = require("...

  1. node.js mongodb exec

Problem: I'm trying to validate when the user only inputted special characters without typing any number with it. I'm using this expression /^\+?[0-9 \.-]+$/ to accept only '+' sign, numbers, dots, ...

Problem: I'm trying to validate when the user only inputted special characters without typing any number with it. I'm using this expression /^\+?[0-9 \.-]+$/ to accept only '+' sign, numbers, dots, ...