使用AJAX使用表单发送表单文件时出错 [英] Error in Sending Form file with form using AJAX

查看:145
本文介绍了使用AJAX使用表单发送表单文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用包含CSV文件的AJAX提交表单。所以我的想法是使用ajax发送表单,通过生成一个表并将处理后的表回调回页面来处理它在不同的文件中。

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.

我拥有的是什么,

<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>

和JavaScript是,

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);
                }
            });
        }); 

我在firebug中遇到这种错误,

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

我在这里做错了什么?请帮助我

What am i doing wrong here ? Please help me

推荐答案

不要将文件传递给构造函数,而是使用append,如:

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

这篇关于使用AJAX使用表单发送表单文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆