Send image with ajax , using jquery validator on submitHandler

那年仲夏 提交于 2019-12-13 09:30:45

问题


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!,


回答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! =)



来源:https://stackoverflow.com/questions/35322901/send-image-with-ajax-using-jquery-validator-on-submithandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!