0

So far I have this form

<form id = "newpost" enctype="multipart/form-data">
    <input type = "text" id = "post_title"  name = "post_title" placeholder = "Post Title"/>
    <textarea id = "post_txt" name = "post_txt" placeholder = "Post Text"></textarea>
    <input type = "file" id = "file_upload" name = "file_upload"/></br>
    <input type = "submit" value = "Post" id = "newpost_btn" name = "newpost_btn"/>
</form>

and this script

var serializedData = $form.serialize();
$.ajax({
    url: "submit.php",
    type: "post",
    data: serializedData
});

but the above script only works on texts. so is there a way to pass the text and images in one request?

Ralph
  • 3
  • 3
  • [This](http://stackoverflow.com/questions/21044798/how-to-use-formdata-for-ajax-file-upload) might be what you are looking for. – Winter Soldier Dec 04 '16 at 23:50
  • does this mean that I could just append the serialized data to the formData? then send it in the form data: formData, – Ralph Dec 05 '16 at 02:10
  • Yes that should be it. Look at the [examples here](http://www.javascripture.com/FormData) – Winter Soldier Dec 05 '16 at 02:28
  • Yes. I guess I have the same problem with the one you have provided. The idea is just to append the data. Anyway I've finally got mine to work. Thanks! – Ralph Dec 05 '16 at 05:26

0 Answers0