Skip to content Skip to sidebar Skip to footer

Formdata Object Not Submitting Via Jquery Ajax Call

I'm using this script to get all values from a form, in order to prepare it for an ajax request: function saveDataAjax(){ var fd = new FormData(); var inputs = document.get

Solution 1:

Add the following to the AJAX call:

processData:false,contentType:false,

So it looks like:

  $.ajax({
       url: '/edit.php',
       data: fd,
       type: 'POST',
       processData: false,  //Add thiscontentType: false, //Add thisdataType: 'html',              
       success: function(data){
           alert(data);
       }
   });

Solution 2:

This is probably not the reason, but just wanted to point it out: i is global here. The idea in JS is towards global abatement. Should probably be var i=...

Solution 3:

this page help you ...:)

<!DOCTYPE html><html><head><scriptsrc="https://code.jquery.com/jquery-3.1.1.min.js"integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="crossorigin="anonymous"></script></head><body><formmethod="post"id="fileinfo"enctype="multipart/form-data">
    file <inputtype="file"name="slug"><br><inputtype="button"id="uploadBTN"value="Stash the file!"></input></form><scripttype="text/javascript">
    $(document).ready(function()
    {
      $('#uploadBTN').on('click', function()
      { 
          var form = $('form').get(0); 
          console.log(form);
          var fd = newFormData(form);
          fd.append('user_id',4);
          fd.append('user_media_category_id',1);
          //console.log(fd);
          fd.append("user_", "This is some extra data");
          $.ajax({
              url: 'http://localhost/yii2/azstudio/project/api/web/v1/user-media/new',  
              type: 'POST',
              data: fd,
              success:function(data){
                  console.log(data);
              },
              error:function(data){
                console.log(data);
              },
              cache: false,
              contentType: false,
              processData: false
          });
      });
    });
  </script></body></html>

Post a Comment for "Formdata Object Not Submitting Via Jquery Ajax Call"