实现同一主域名上传文件
1、在调用接口页面加入:document.domain = "izsgold.com";
2、接口请求返回加入:<script>document.domain = "xxxx.com";</script>+返回的数据
3、dataType: 'json',过滤json数据中的html
uploadHttpData: function( r, type ) {
var data = !type;
data = type == "xml" || data ? r.responseXML : r.responseText;
// If the type is "script", eval it in global context
if ( type == "script" )
jQuery.globalEval( data );
// Get the JavaScript object, if JSON is used.
if ( type == "json" ){
var result = data.replace(/<[^>]+>/g,"");
data = eval( "data = " + result );
}
// evaluate scripts within html
if ( type == "html" )
jQuery("<div>").html(data).evalScripts();
return data;
}
参考:http://www.ueffort.com/jqueryajaxfileupload-js-duo-wen-jian-shang-chuan-chuan-zhi-kua-yu/
本文介绍了一种通过修改文档域名称来实现同一主域名下的跨域文件上传的方法。具体步骤包括在调用接口页面设置document.domain,在接口返回中加入特定脚本及过滤返回的JSON数据中的HTML内容。
1521

被折叠的 条评论
为什么被折叠?



