首页 > 解决方案 > formData object Uncaught TypeError: 非法调用

问题描述

虽然这个问题有很多帖子,但我仍然卡住无法解决这个问题。下面是我的简单代码。想将数据从csv导入mysql。

    <div class="panel panel-default">
          <div class="panel-heading">Import Data From Excel or CSV File to Mysql using PHPSpreadsheet</div>
          <div class="panel-body">
                <div class="table-responsive">
                    <span id="message"></span>
              <form method="post" id="import_excel_form" enctype="multipart/form- 
   data">
                <table class="table">
                  <tr>
                    <td width="25%" align="right">Select Excel File</td>
                    <td width="50%"><input type="file" name="import_excel" /></td>
                    <td width="25%"><input type="submit" name="import" id="import" class="btn btn-primary" value="Import" /></td>
                  </tr>
                </table>
                  </form>
                    <br />
              
                </div>
              </div>
           </div>

ajax调用下面的Javascript:

<script>
$(document).ready(function(){
  $('#import_excel_form').on('submit', function(event){
event.preventDefault();
alert("lk");

$.ajax({
            type:"GET",
            url: "<?php echo base_url('billing/importsellcomCDR'); ?>",
            data: new FormData(document.getElementById("import_excel_form")),
            contentType: "application/json",
            datatype: "json",
            success: function(){ 
                console.log("test"); 
            },
            error: function(xhr, textStatus, error){
                console.log(xhr.statusText);
                console.log(textStatus);
                console.log(error);
                }
        });
  });
});
</script>

它给出了错误 Uncaught TypeError: Illegal invocation 请知道我在哪里做错了。谢谢

标签: javascriptajaximportmultipartform-data

解决方案


推荐阅读