惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
罗磊的独立博客
F
Fortinet All Blogs
人人都是产品经理
人人都是产品经理
量子位
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
B
Blog RSS Feed
腾讯CDC
博客园_首页
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
博客园 - Franky
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
D
Docker
P
Privacy & Cybersecurity Law Blog
S
Securelist
V
V2EX
Jina AI
Jina AI
阮一峰的网络日志
阮一峰的网络日志
T
Tor Project blog
The Hacker News
The Hacker News
Microsoft Azure Blog
Microsoft Azure Blog
AWS News Blog
AWS News Blog
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
Recent Announcements
Recent Announcements
Cloudbric
Cloudbric
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Latest news
Latest news
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recorded Future
Recorded Future
V2EX - 技术
V2EX - 技术

博客园 - ZEKELOVE

学习云计算基础总结 初识物联网的无线(长/短)距离技术总结 初识物联网知识入门总结 学习React框架-总结 WEB开发-HTML入门学习总结 WEB开发-CSS入门学习总结 WEB开发-HTML入门学习总结 华为RPA机器人学习(2) 华为RPA机器人学习(1) Python学习(1)-基础语法学习丨【生长吧!Python】 《Python入门》学习笔记(3) 《Python入门》学习笔记(2) 《Python入门》学习笔记(1) 《基于华为云DevCloud的托马斯商城》的学习笔记 Vue+Vue-router微信分享功能 Angular4中路由Router类的跳转navigate 2017浅谈面试(一) iscroll简单使用说明 文本框输入内容放大显示和格式化插件
jQuery File Upload跨域上传
ZEKELOVE · 2015-12-18 · via 博客园 - ZEKELOVE

  最近在做一个一手粮互联网项目,方案为前后端分离,自己负责前端框架,采用了Requirejs+avalonjs+jquery三个框架完成。

  前后端通过跨域实现接口调用,中间也发现了不少问题,尤其是在富文本编辑器和上传插件跨域的处理过程中,费劲了脑汁,总算解决了。

  上传选择了jQuery File Upload,兼容性还是相对不错,并且支持跨域,但是没有一个完整的跨域Demo,只能看源码找帮助。

  下载地址:https://github.com/blueimp/jQuery-File-Upload

  页面实现方法:

  页面引入:

  <link rel="stylesheet" type="text/css" href="../../src/widget/jQueryFileUpload/css/jquery.fileupload.css">
  <link rel="stylesheet" type="text/css" href="../../src/widget/jQueryFileUpload/css/jquery.fileupload-ui.css">
  <script type="text/javascript" src=".../../src/widget/jQueryFileUpload/js/vendor/jquery.ui.widget.js"></script>
  <script type="text/javascript" src=".../../src/widget/jQueryFileUpload/js/jquery.iframe-transport.js"></script>
  <script type="text/javascript" src=".../../src/widget/jQueryFileUpload/js/jquery.fileupload.js"></script> 上传页面
  <input id="fileupload" type="file" name="files" multiple>

 1 $('#fileupload').fileupload({
 2             url: config.getUrl()+"upload!upload.do",
 3             type:"POST",
 4             dataType:"json",
 5             autoUpload : true,
 6             acceptFileTypes: /(\.|\/)(jpe?g|png)$/i,
 7             formData: {model:1},
 8             forceIframeTransport: true,
 9             redirectParamName:"callUrl",
10             redirect:"http://"+window.location.host+"/app/callupload.html?",//回调页面
11             done: function (e, data) {
12                 $.each(data.result.files, function (index, file) {
13                     model.fileVO.push({attach_root_id:file.id,file_path:file.url});
14                 });
15             },
16             fail:function(e,data){
17                 console.log("上传失败:"+data.errorThrown);
18             }
19         });

View Code

  创建一个回调页面callupload.html

<body>
    <script type="text/javascript">
        document.body.innerText=document.body.textContent=decodeURIComponent(window.location.search.slice(1));
    </script>
</body>

View Code

  上传后台:

1 string result = file.FileName;
2              context.Response.Headers.Add("Cache-Control", "no-cache");
3              context.Response.AddHeader("Access-Control-Allow-Origin", "*");
4              context.Response.AddHeader("Access-Control-Allow-Headers", "x-requested-with");
5              context.Response.AddHeader("Location", callUrl + "?msg=" + result);
6              context.Response.Redirect(callUrl + "?msg=" + result); 

View Code

欢迎大家来交流!

喜欢H5,web开发的朋友可以加群:374166122

作者:zeke     
          出处:http://zhf.cnblogs.com/
          本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。