-2

I trying to send two images with ajax (inside submitHandler) after using jquery validator plugin and i don't know hoy i cant take and send this image by ajax.

My code here:

var submitHandler = function(form) {

    var formData = form[0];
    var formData = new FormData(formData);

    $.ajax({
        url: 'function/savePreInscripcion.php',
        type: 'POST',
        data: formData,
        mimeType: "multipart/form-data",
        contentType: false,
        cache: false,
        processData: false,
        success: function(data){
            alert(data);
        }
    });
};

but this dont work..

this display this error:

TypeError: Argument 1 of FormData.constructor does not implement interface HTMLFormElement.
var formData = new FormData(formData);

so.. what's worng here?

Thnx for the help!,

Sparky
  • 98,165
  • 25
  • 199
  • 285
Fakux
  • 101
  • 1
  • 4
  • `FormData` works as a set of key-value pairs. https://developer.mozilla.org/en-US/docs/Web/API/FormData – DPac Feb 10 '16 at 18:22

1 Answers1

-1

I resolve this..

Just change a little party on my code..

var submitHandler = function(form) {
    $.ajax({
        url: 'function/savePreInscripcion.php',
        type: 'POST',
        data: new FormData(form),
        mimeType: "multipart/form-data",
        contentType: false,
        cache: false,
        processData: false,
        success: function(data){
            alert(data);
        }
    });
};

Just I change the call to the form and put this directly on the data whit the next code: "data: new FormData(form)" and it work fine! =)

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Fakux
  • 101
  • 1
  • 4