0

I am using FormData to send multipart/form-data and getting it value in PHP, it works fine in Chrome but not in Firefox.

here is my JS

$.ajax({
    type: "POST",
    url: postUrl,
    dataType: "json",
    data: new FormData($("#form")[0]),
    processData: false,
    contentType: false,
    success: function (response) {
    }
});

My HTML code,

<form action="" method="post" enctype="multipart/form-data" id="form"> 
     <input type="text" class="form-control" value="" id="name" name="name">   
     <input type="file" id="resourceFile" name="resourceFile"> 
</form>

Here is my Php code

echo $_POST["name"]  // name field is in form

In chrome I am getting value for name but in Firefox it's saying 
Undefined index: name.


This i am getting on print_r($_POST) for Firefox 
Array ( [-----------------------------183019406712953243052078205169 Content-Disposition:_form-data;_name] => "name" sdgdxgf -----------------------------183019406712953243052078205169-- ) 

This i am getting on print_r($_POST) for Chrome 
Array ( [name] => sdgdxgf )
Sanjeev
  • 1
  • 3
  • Which firefox version are you using? Besides, please share your HTML form aswell. – briosheje Mar 30 '16 at 13:07
  • I am using Firefox 45.0 for Ubuntu, Here is my HTML form
    and data: new FormData($("#form")[0]) i am using.
    – Sanjeev Mar 30 '16 at 13:49
  • Please edit the question and include the html, that way it can be formatted and easier to read :) – mattumotu Mar 30 '16 at 13:56
  • If you try `print_r($_POST);` in the php this might help with debugging – mattumotu Mar 30 '16 at 13:57
  • This i am getting on print_r($_POST) for Firefox Array ( [-----------------------------183019406712953243052078205169 Content-Disposition:_form-data;_name] => "name" sdgdxgf -----------------------------183019406712953243052078205169-- ) This i am getting on print_r($_POST) for Chrome Array ( [name] => sdgdxgf ) – Sanjeev Mar 30 '16 at 14:18
  • Formatted question with posting HTML given by OP by comment – Vinoth Krishnan Mar 30 '16 at 14:26
  • This is wrong: `data: new FormData("form")`. According with [MDN](https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects) you must to pass by argument the DOM object, not a string: `data: new FormData(document.getElementsByTagName('form')[0])`. – Marcos Pérez Gude Mar 30 '16 at 14:29
  • yes, i am using data: new FormData($("#form")[0]) – Sanjeev Mar 30 '16 at 14:34
  • 1
    You have to append the data and send. Please check the link [Check this link](http://stackoverflow.com/questions/21044798/how-to-use-formdata-for-ajax-file-upload) – DarkRose Mar 30 '16 at 14:35
  • checked with using append, still same issue. Actually it was working before(2 weeks back) but now it's not working anymore – Sanjeev Mar 30 '16 at 14:41

0 Answers0