ajaxfileupload上传文件,返回json数据报错的问题。 Resource interpreted as Document but transferred with MIME type ap
来源:互联网 发布:杭州市行知小学 编辑:程序博客网 时间:2024/05/21 15:42
转自:http://www.cnblogs.com/losedo/p/4235674.html
在使用ajaxfileupload上传文件的时候,文件上传成功了,但是返回的json数据一直解析不了。一直提示:Resource interpreted as Document but transferred with MIME type application/json,从字面上理解返回的是文档不能转换为json。但是从服务器那边返回的response里data-type确实是applicaiton/json。困扰很久,查看ajaxfileupload源代码发现,其实ajaxfileupload其实使用iframe+form的方式实现异步上传文件的,如下:
//////////////////////////////////////////////////////////////////
//穿件form表单函数
createUploadForm: function (id, fileElementId, data) {
//create form
var formId = 'jUploadForm' + id;
var fileId = 'jUploadFile' + id;
var form = jQuery('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
//上传调用接口
ajaxFileUpload: function (s) {
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
s = jQuery.extend({}, jQuery.ajaxSettings, s);
var id = s.fileElementId;
var form = jQuery.createUploadForm(id, s.fileElementId, s.data); //创建form表单
var io = jQuery.createUploadIframe(id, s.secureuri);//创建Iframe
////////////////////////////////////////////////////////
知道了上传流程,明白了问题出现在哪里了,是用Iframe的时候,返回的时候会添加上html和body标签。jquery不能直接解析的话,只能自己解析了。
ajaxfileupload调用的时候dataType不用设置,使用默认text/html.返回的数据作处理:
var str = $(data).find("body").text();//获取返回的字符串
var json = $.parseJSON(str);//把字符串转化为json对象
阅读全文
0 0
- ajaxfileupload上传文件,返回json数据报错的问题。 Resource interpreted as Document but transferred with MIME type ap
- 关于easyui Resource interpreted as Document but transferred with MIME type application/json
- Resource interpreted as Document but transferred with MIME type application/json ...
- ThinkPHP Resource interpreted as Document but transferred with MIME type application/json 导致js无效
- Resource interpreted as Document but transferred with MIME type application/json:
- 关于ajaxFileUpload无法解析json的问题(Resource interpreted as Document but transferred with ……)
- Chrome 报 Resource interpreted as Script but transferred with MIME type text/plain 警告的解决办法
- Chrome 报 Resource interpreted as Script but transferred with MIME type text/plain 警告的解决办法
- 关于chrome Resource interpreted as Script but transferred with MIME type text/html的问题
- 关于chrome Resource interpreted as Script but transferred with MIME type text/html的问题
- 关于 Resource interpreted as Script but transferred with MIME type text/plain问题的处理
- 样式加载不出来,浏览器控制台报错:Resource interpreted as Stylesheet but transferred with MIME type text/html
- Java过滤器引发的异常:Resource interpreted as Stylesheet but transferred with MIME type text/html
- 谷歌浏览器下在文本框中敲回车会下载。。。Resource interpreted as Document but transferred with MIME type application/json
- golange 错误如下 Resource interpreted as Script but transferred with MIME type text
- Resource interpreted as Stylesheet but transferred with MIME type text/html:以及Uncaught SyntaxError:
- Resource interpreted as Image but transferred with MIME type text/plain 警告解决方案
- Resource interpreted as Script but transferred with MIME type text/html
- EasyPlayer rtsp播放器源码解析之64位编译方案
- 个人总结php笔试题四
- java-同步锁synchronized
- MySql主从复制
- IDEA中SonarLint的配置
- ajaxfileupload上传文件,返回json数据报错的问题。 Resource interpreted as Document but transferred with MIME type ap
- QT 取消ui->PushButton的边框
- mkdir -p
- public protected private区别
- SpringBoot初始教程之Servlet、Filter、Listener配置(七)
- EXT3.4-gridpanel定时刷新滚动条自动滚动
- 利用Android Studio的 Monitor Memory 查找内存泄漏
- Java NIO 系列教程
- PHP数组实际占用内存大小的分析