-1

I am trying to send a image with AJAX.Though I keep on getting this error.

TypeError: 'append' called on an object that does not implement interface FormData.

enter image description here

This is my code:

$(document).ready(function(){

$('#post').on('submit', function(e){
    e.preventDefault();
    var data = new FormData(this);
    $.ajax(
        {
            url: 'post_ajax/savePost',
            type: 'POST',
            dataType: false,
            contentType: false,
            pocessData: false,
            data: data,
            success: function (resultado) {
               console.log(resultado)
            }
        }
    ).done(
        function(json){
            if(json.data){
                console.log('Ajax correcto');
            }else{
                console.log('No se ha podido guardar el post');
            }
        }
    ).fail(
        function(){
            console.log('fallo en ajax');    
        }    
    );
});

});

And this is my html form:

<form id="post" enctype='multipart/form-data'>
     <textarea id="texto" rows="4" cols="50" placeholder="¿Que esta pasando?"></textarea> 
     <input type="file" id="media"/>
     <input type="submit" value="Submit"/>
</form>

Thanks you!!

3
  • Can you include a non-minified version of jquery plus the stack trace generated by the error? Commented May 7, 2018 at 16:11
  • 1
    pocessData -> processData (typo) this is likely the cause, as without this, jquery might do something with the data, thus potentially causing an error. Commented May 7, 2018 at 16:11
  • See stackoverflow.com/questions/25390598/… Commented May 7, 2018 at 16:23

1 Answer 1

-2

I found this answer here:

var formData = new FormData(form[0]);
    formData.append('texto', texto);
    formData.append('media', archivo);

     $.ajax({
        url: 'post_ajax/savePost',
        data: formData,
        cache: false,
        contentType: false,
        processData: false,
        type: 'POST',
          success: function(data){
             console.log(data);
          }
     });

Thanks everyone for all

Sign up to request clarification or add additional context in comments.

1 Comment

i mean... that answer has the proper spelling of process. Did you first attempt your existing code with the fixed typo?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.