0

Is there a possibility to pass image file in one function with dataString?

I've got something like this:

 $.ajax({
        type: "POST",
        url: "../insert.php",
        data:  dataString, 
        success: function(response){
             console.log(response);
        }
      });

and everything works fine. Except the image is not send to php, only the name - thats pretty obvious. But how to achieve that?

user3267302
  • 303
  • 4
  • 14
  • This question has been answered before. http://stackoverflow.com/questions/21164365/how-to-send-image-to-php-file-using-ajax – Nitin May 07 '16 at 07:39
  • yes, but it's only about sending an image, not two types of data (image and string) – user3267302 May 07 '16 at 07:42
  • Ok, i've managed to make it trough this: http://stackoverflow.com/questions/21060247/send-formdata-and-string-data-together-through-jquery-ajax – user3267302 May 07 '16 at 08:14

1 Answers1

0

Check this link: How to send image to PHP file using Ajax?

The accepted answer should send all inputs (string and file).

To add extra inputs, you can try:

var extraInput = document.createElement('input');
extraInput.type = 'text';
extraInput.name = 'name';
extraInput.value = '...';

formData.appendChild(extraInput);
Community
  • 1
  • 1
Nitin
  • 898
  • 1
  • 9
  • 25
  • Ok, i've made it trough this: http://stackoverflow.com/questions/21060247/send-formdata-and-string-data-together-through-jquery-ajax – user3267302 May 07 '16 at 08:15