GIT 下载地址

https://github.com/blueimp/jQuery-File-Upload

亲测HTTPS HTTP跨域无压力

不用自带的DEMO

用下面的DEMO

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery File Upload Example</title>
</head>
<style>
.bar {
height: 18px;
background: green;
}
.content{
width: 100%;text-align: center;margin-top: 70px;
}
#progress{
border-radius:6px;width: 300px;background: red;
margin: 10px auto;
}
</style>
<body> <div class="content">
<input id="fileupload" type="file" name="upfile" ">
<div id="progress">
<div class="bar" style="width: 0%;"></div>
</div>
<img id="uploadimg" src="__PUBLIC__/images/bg.jpg" width="400px" height="408px"/>
</div> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="js/vendor/jquery.ui.widget.js"></script>
<script src="js/jquery.iframe-transport.js"></script>
<script src="js/jquery.fileupload.js"></script>
<script> $('#fileupload').fileupload({
url: "",
type:"POST",
dataType:"json",
autoUpload : true,
acceptFileTypes: /(\.|\/)(jpe?g|png)$/i,
      

        //跨域
        forceIframeTransport: true,

            formData: {
action:"UploadVMKImagePath",
param:JSON.stringify({
projectId:12343,
fileType:"任务日志图片"
})
}, done: function (e, data) {
console.log(e);
console.log(data);//data里面包含了服务端返回的字段
},
fail:function(e,data){
console.log("上传失败:"+data.errorThrown);
}, progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100);
$('#progress .bar').css(
'width',
progress + '%'
);
}, }); </script>
</body>
</html>

中间遇到的问题是,一旦采用了跨域 就会使用FROM包含 iframe的方式上传,所以在done函数里是无法直接拿到服务器的返回值的。

这个插件定义的是这样 如果采用了iframe方式,必须要设置一个CALL参数,当服务器接受完你的上传数据 回CALL你设置的页面

redirectParamName:"callUrl",
redirect:"http://"+window.location.host+"/app/callupload.html?",//回调页面

很显然服务端要接受和处理你这个callurl,不过这次的项目中,目标上传服务器的处理完上传后,是直接把数据写到页面的。而不是去CALL什么地址。。

没法。。只有从其他地方下手了。

通过调试发现

既然iframe,上传完成后服务端的返回内容一定iframe里面的。

jquery.iframe-transport.js

在这个文件里的下面代码中可以记录下服务器返回的结果

 window.setTimeout(function () {
// Removing the form in a setTimeout call
// allows Chrome's developer tools to display
// the response result console.log("【upload-iframe】");
console.log(iframe); //form.remove();
}, );
iframe 这个参数在jquery.iframe-transport.js中就定义好了,输出看看就知道了

文件上传跨域解决方案-jQuery-File-Upload的更多相关文章

  1. .net文件上传,客户端用jquery file upload

    <%@ WebHandler Language="C#" Class="Handler" %> using System; using System ...

  2. 文件上传报错:Unknown: file created in the system's temporary directory

    nginx+php下文件上传成功,但会有错误提示如下: <b>Notice</b>:  Unknown: file created in the system's tempor ...

  3. springmvc文件上传 参数为MultipartFile 转换为File

    package cn.com.mcd.controller;import java.io.File;import java.io.IOException;import java.io.Serializ ...

  4. SpringBoot文件上传异常之提示The temporary upload location xxx is not valid

    原文: 一灰灰Blog之Spring系列教程文件上传异常原理分析 SpringBoot搭建的应用,一直工作得好好的,突然发现上传文件失败,提示org.springframework.web.multi ...

  5. UEditor单图上传跨域问题解决方案

    UEditor UEditor是百度团队提供的富文本编辑器 git地址为:https://github.com/fex-team/ueditor 在最近的项目中使用了该插件作为项目的富文本编辑器 由于 ...

  6. kindedit,uedit 上传跨域返回

    1.kindedit 跨域上传图片的时候,a.com 上传到b.com接收图片服务器,然后返回图片地址. 2.一般如果不做任何处理是获取不到返回的信息的.原因是跨域了 3.所以一般在上传成功后,在跳转 ...

  7. Win2008或IIS7的文件上传大小限制解决方案

    默认情况下,IIS7的上传限制为200K.当上传文件小于30M时,可以通过如下方法设置:在iis7中找到asp设置,在“asp”的“限制属性”中最后一行“最大请求主体限制”,修改该值为你所想要的,如2 ...

  8. 在系统下文件上传报错:The temporary upload location [/tmp/tomcat.xxx/work/Tomcat/localhost/ROOT] is not valid

    线上的系统中长时间不访问时不能上传文件了,出现如下错误: 2019-03-11 23:37:42.741 ERROR 66505 --- [nio-8081-exec-3] o.a.c.c.C.[.[ ...

  9. springboot 文件上传 java.io.IOException: The temporary upload location [/tmp/xx] is not valid

    转自:http://meia.fun/article/1541578061808 首先分析下出现问题的原因:linux 下的 /tmp 目录,是用来存储由各种程序创建的临时文件的地方.一些配置,导致系 ...

随机推荐

  1. python实现pow函数(求n次幂,求n次方)

    目录 类型一:求n次幂 类型二:求n开方 类型一:求n次幂 实现 pow(x, n),即计算 x 的 n 次幂函数.其中n为整数.pow函数的实现--leetcode 解法1:暴力法 不是常规意义上的 ...

  2. 使用IntelliJ IDEA配置Tomcat

    一.下载Tomcat 1.进入官网http://tomcat.apache.org/,选择download,下载所需Tomcat版本. 此处我们选择下载最新版本Tomcat 9. 注意有zip和exe ...

  3. C语言——for循环和while循环的效率区别——类似哨兵思想

    int ID_Conv_Sentinel(int u16device_cfg_num) { int i8id; int size=0; int i=0; size = sizeof(Device_ID ...

  4. [codeforces][dp]

    链接:https://ac.nowcoder.com/acm/problem/21314来源:牛客网 题目描述 牛牛正在打一场CF 比赛时间为T分钟,有N道题,可以在比赛时间内的任意时间提交代码 第i ...

  5. C# 判断一个string型的时间格式是否正确

    在项目开发过程中,由于各种坑爹的需求,我们可能需要用户自己手动输入时间,不过这种功能一般都出现在自己家的后台里面,咳咳,言归正传.既然如此,那么这个时候我们就需要对用户手动输入的时间格式进行验证,方法 ...

  6. 更改ejs模板引擎的后缀为html

    安装 EJS 在项目目录右键->Open Command Prompt Here 输入 npm install ejs 打开app.js //app.set('view engine', 'ja ...

  7. php注意事项|要点

    1. 用单引号代替双引号来包含字符串,这样做会更快一些.因为 PHP 会在双引号包围的 字符串中搜寻变量,单引号则不会,注意:只有 echo 能这么做,它是一种可以把多个字符 串当作参数的“函数”(译 ...

  8. Django-中间件实现1分钟内只允许三次访问

    代码 class Throttle(MiddlewareMixin): def process_request(self, request): # 1. 拿到用户请求的IP # print(reque ...

  9. CSPS模拟69-72

    模拟69: T1,稍数学,主要还是dp(转移莫名像背包???),当C开到n2时复杂度为n4,考场上想了半天优化结果发现n是100,n4可过 #include<iostream> #incl ...

  10. win10 开启全局代理

    1. 打开设置 2. 点击“网络和Internet” 3.设置手动代理 . 设置完成后就可以愉快的玩耍啦