Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when using formData jquery

I am uploading an image using a form. For that I have to use formData. My code is returning an error:

Uncaught TypeError: Illegal invocation

Here is my code:

var url = ajaxurl,
    formData = new FormData(),
    _this = this,
    form = $(this.$avatarForm[0]),
    avatar_src = form.find('.avatar_src').val(),
    avatar_data = form.find('.avatar_data').val(),
    action = form.find('.action').val();
    formData.append("avatar_src", avatar_src);
    formData.append("avatar_data", avatar_data);
    formData.append("action", action);
    console.log(formData);

$.ajax(url, {
    type: 'post',
    data: formData,
    dataType: 'json',
    success: function (data) {
        _this.submitDone(data);
    }
});

1 Answers

you can try like this

$.ajax({
    url : url,
    type: 'post',
    data: formData,
    dataType: 'json',
    processData: false,
    success: function (data) {
        _this.submitDone(data);
    }
});
like image 96
Akash Chavda Avatar answered Dec 07 '25 22:12

Akash Chavda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!