Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
Hi,

I have a form with one upload control and some text fields.

i am sending the formdata values to the controller with ajax.

Here am facing one problem i.e am able to get the formdata values in IE and Mozilla but not in chrome. Please let me know the reason.

Here is my code snippet.

var fileUpload = $("#file").get(0);

 var files = fileUpload.files;

 var fileData = new FormData();

for (var i = 0; i < files.length; i++)
{

    fileData.append(files[i].name, files[i]);

}
 
 fileData.append("textfield1", $('#textfield1').val());

 fileData.append("textfield2", $('#textfield2').val());

 fileData.append("textfield3", $('#textfield3').val());

 fileData.append("textfield4", $('#textfield4').val());
 
xhr = $.ajax({

                url: 'Home/Index',

                type: 'POST',

                dataType: "JSON",

                contentType: false, // Not to set any content header 

                processData: false, // Not to process data 

                data: fileData
    })


Thanks in advance.


What I have tried:

I tried with IE and Mozilla it is working fine.
Posted
Updated 29-Jun-16 6:29am
Comments
Richard Deeming 29-Jun-16 12:17pm    
Chrome has supported FormData since version 7. If your code works in IE and Firefox, it should also work in Chrome.

You'll need to debug your code to see what's going wrong.

You could also try disabling any Chrome extensions you have installed, in case one of them is interfering with the script.

1 solution

To start with, check out compatibility chart: FormData — Web APIs | MDN.

See the section "Browser compatibility".

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900