-
遇到的问题
浏览器上显示已接收到返回数据,但不经success方法
error里也没有接收到值 -
解决:是由于跨域引起的
(1) java后端修改返回值return "<script>document.domain = location.hostname;</script>"+JSON.toJSONString(apiMsg);
(2) 前端调用ajaxFileUpload添加
document.domain = location.hostname;//添加 var fid = this.data.fid?this.data.fid:'root'; var fileElementIds = new Array(); fileElementIds.push('proclaimedFile1'); $.ajaxFileUpload ({ url: 'http://localhost:8080/restful/api/safe/symmetry/encryptFile/1.shtml', secureuri: false, fileElementId:fileElementIds, data: {"key": $("#key1").val(),"moshi": $("#moshi1").val(), "fid":fid}, dataType : 'json', success:function(e){ console.log('成功') if (e.status === 0) { layer.msg(e.msg) } }, error:function(e){ layer.msg("上传失败") } })
(3)插接修改
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") data = $.parseJSON( data );//修改 if (type == "html") jQuery("<div>").html(data).evalScripts(); return data; }
ajaxFileUpload文件上传,跨域问题
最新推荐文章于 2024-06-26 09:55:19 发布