Error:Sending Form file with form using AJAX

0 votes

I am trying to submit form using AJAX that contains CSV File. So the idea is sending the form using ajax, process it in different file by generating a table and call back the processed table back into the page.

What i Have is this,

<form id="uploadXls" action="" method="post" enctype="multipart/form-data">
      <input id="uploaderFile" type="file" class="file"><br/>
      <button type="button" class="btn btn-orange pull-right" name="btnSubmit" id="btnSubmit"><i class="fa fa-download"></i> SHOW FILE CONTENT</button>
</form>

and the JavaScript is,

$("#btnSubmit").click(function(){
            $.ajax({
                type: 'POST',
                url: '../../content/maindiv_content/drawing/divpages/process_xls_file.php',
                data: new FormData(this),
                contentType: false,
                cache: false,
                processData: false,
                success: function (response, textStatus, jqXHR) {
                  $("#showFileContentTable").html(data);
                }
            });
        }); 

and im getting this kind of error in firebug,

TypeError: Argument 1 of FormData.constructor does not implement interface HTMLFormElement.
http://infserver/WeltesTankage/dist/js/jquery-1.10.2.min.js line 4 > eval
Line 14

How to solve this error?

Jun 16 in PHP by kartik
• 20,980 points
64 views

1 answer to this question.

0 votes

Hello @kartik,

Don't pass the files into the constructor, but use append, like:

var formData = new FormData();
formData.append('file', $('input[type=file]')[0].files[0]);
data:  formData

Hope this will solve your error!!

Thank you!!

answered Jun 16 by Niroj
• 44,800 points

Related Questions In PHP

0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27 in PHP by Niroj
• 44,800 points
57 views
0 votes
1 answer

How can you upload a file using PHP?

Hello, To upload a file by using PHP, ...READ MORE

answered Mar 27 in PHP by Niroj
• 44,800 points
63 views
0 votes
1 answer

Error:“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

Hello @kartik, The best way for getting input string is: $value ...READ MORE

answered Apr 1 in PHP by Niroj
• 44,800 points
2,249 views
0 votes
1 answer

Error:PDOException SQLSTATE[HY000] [2020] No such file or directory in php?

Hello, I checked php -i | grep pdo and noticed ...READ MORE

answered Apr 2 in PHP by Niroj
• 44,800 points
77 views
0 votes
1 answer

How do I post a form in laravel 5 using ajax?

Hello @kartik, You can solve this error by ...READ MORE

answered Jun 11 in Java-Script by Niroj
• 44,800 points
54 views
0 votes
1 answer

How to return AJAX response Text?

Hello @kartik, What you need to do is ...READ MORE

answered Jun 18 in Java-Script by Niroj
• 44,800 points
40 views
0 votes
1 answer

How do I modify the URL without reloading the page?

Hii @kartik, HTML5 introduced the history.pushState() and history.replaceState() methods, which allow you ...READ MORE

answered Jun 19 in Java-Script by Niroj
• 44,800 points
165 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 44,800 points
1,391 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13 in PHP by Niroj
• 44,800 points
125 views
0 votes
1 answer

Complete PHP form with proper validation and syntax

Hey @kartik, It's quite simple to have php ...READ MORE

answered Feb 19 in PHP by Niroj
• 44,800 points
79 views