如何使用Formdata上传文件

时间:2015-11-05 18:43:08

标签: javascript jquery ajax

我使用ajax上传文件跨域。我认为这个bug是js的一部分。

但我无法弄清楚究竟是什么错误。

ANALYZE TABLE p_7 COMPUTE STATISTICS noscan

这是我的js

<form id="upload">
      <div class="control-group">
          <div class="controls">
              <input id="file" name="file" type="file">
          </div>
          <div class="form-group">
              <button class="btn btn-primary" onclick="Submit()" type="button">submit</button>
          </div>
      </div>
</form>

2 个答案:

答案 0 :(得分:0)

当用户点击该按钮时,您正在调用函数<div style="width: 1024px; margin: 0 auto;"> <div style="position: absolute; height: 500px;"> </div> <div style="height: 100px;"> It's at the top of the upper div. </div> </div> ,但它未在您的js中定义。这应该有效:

Submit()

答案 1 :(得分:0)

dataType:'jsonp',

JSONP与POST请求(文件上传需要)不兼容。

使用jQuery支持的任何其他数据类型。

由于您正在发出跨域请求,因此您需要目标服务器通过CORS授予您权限。

相关问题