源:
方式一:http://www.iteye.com/problems/24042 lovewhzlq解答详细透彻
方式二http://liwx2000.iteye.com/blog/1540321
评:
1.解决方式一resp.setContentType("text/html;charset=UTF-8");
将response 数据格式 设置text/html
解决方式二 假如contentType="application/json"数据格式没法改 ,那么将responseText 进行替换 <pre> </pre>替换为空
2.ajaxfileupload 支持到jquery1.2 1.7中少了handlererror函数 加上即可
handleError: function( s, xhr, status, e ) {
// If a local callback was specified, fire it
if ( s.error ) {
s.error.call( s.context || s, xhr, status, e );
}
// Fire the global callback
if ( s.global ) {
(s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
}
},
json字符串转为 对象 方法
function strToJson(str){
var json = eval('(' + str + ')');
return json;
}
方式一:http://www.iteye.com/problems/24042 lovewhzlq解答详细透彻
方式二http://liwx2000.iteye.com/blog/1540321
评:
1.解决方式一resp.setContentType("text/html;charset=UTF-8");
将response 数据格式 设置text/html
解决方式二 假如contentType="application/json"数据格式没法改 ,那么将responseText 进行替换 <pre> </pre>替换为空
2.ajaxfileupload 支持到jquery1.2 1.7中少了handlererror函数 加上即可
handleError: function( s, xhr, status, e ) {
// If a local callback was specified, fire it
if ( s.error ) {
s.error.call( s.context || s, xhr, status, e );
}
// Fire the global callback
if ( s.global ) {
(s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
}
},
json字符串转为 对象 方法
function strToJson(str){
var json = eval('(' + str + ')');
return json;
}
解决Ajax与JSON数据格式问题
本文介绍了解决Ajax请求返回HTML而非预期JSON格式的问题,提供了两种解决方案:一是通过设置响应内容类型为text/html;二是如果无法更改内容类型,则通过预处理响应文本。此外,还介绍了如何为较旧版本的jQuery添加错误处理函数,并提供了一种将JSON字符串转换为对象的方法。
546

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



