$.ajax的dataType属性
$.ajax({
type : 'post',
url : "12.ajax_JSON.php",
dataType : 'html',
success:function (msg,textStatus) {
console.log(msg);
},
error:function(msg){
alert(msg.status);
});
$.ajax({
type : 'post',
url : "12.ajax_JSON.php",
dataType : 'html',
success:function (msg,textStatus) {
console.log(msg);
},
error:function(msg){
alert(msg.status);
});
dataType值如果为’html’, 后台返回的json字符串。
dataType值如果为’json’, 后端返回的字符串尝试通过JSON.parse()尝试解析为js对象。
dataType值如果为’text’, 后台返回的json字符串。
本文深入探讨了jQuery中$.ajax方法的dataType属性的作用。详细解释了当dataType设置为'html'、'json'和'text'时,后端响应如何被jQuery处理,帮助开发者更好地掌握异步请求的数据类型管理。

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



