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, 2020 in PHP by kartik
• 37,520 points
4,034 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, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
0 answers

Form submit with AJAX passing form data to PHP without page refresh

Can anyone tell me why this bit ...READ MORE

Jul 29, 2022 in PHP by Kithuzzz
• 38,000 points
1,848 views
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, 2020 in PHP by Niroj
• 82,840 points
1,295 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, 2020 in PHP by Niroj
• 82,840 points
854 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, 2020 in PHP by Niroj
• 82,840 points
37,526 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, 2020 in Java-Script by Niroj
• 82,840 points
2,827 views
0 votes
1 answer

How to return AJAX response Text?

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

answered Jun 18, 2020 in Java-Script by Niroj
• 82,840 points
12,036 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 20, 2020 in Java-Script by Niroj
• 82,840 points
5,505 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 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, 2020 in PHP by Niroj
• 82,840 points
3,318 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, 2020 in PHP by Niroj
• 82,840 points
1,540 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP