jquery1.8以上的版本和以前的版本区别
jQuery1.8和更高的版本需要注意的地方.不要忘了,.success()和.error()仍然在jQuery的1.9.1版本中被支持,所以它不会破坏你原来的代码和插件的使用。我也制定了一些新的Query的1.9 +的jQuery.ajax()的例子。
弃用通知:jqXHR.success(),jqXHR.error(),和jqXHR.complete()回调在jQuery 1.8中是被弃用的。所以要准备你的代码以备这些方法最终被去除,使用jqXHR.done(),jqXHR.fail(),和jqXHR.always()来代替。
使用jQuery 1.8以前版本AJAX获取HTML。
$.ajax({
url: 'test.html',
dataType: 'html',
success: function (data, textStatus, xhr)
{
console.log(data);
},
error: function (xhr, textStatus, errorThrown)
{
console.log('error: '+textStatus);
}
});
使用jQuery 1.8 +的AJAX获取HTML
// cache: false is used to fetch the latest version
$.ajax({
url: "test.html",
cache: false
})
.done(function(data, textStatus, jqXHR)
{
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown)
{
console.log('error: '+textStatus);
});
多步回调可以是$.ajax()请求中指定回调方法中的一个。 回调方法 .done(), fail(), always(), then.()是jqXHR对象的所有约定的方法。所有这些回调方法触发一次的$.ajax()进程终止。预订回调在他们注册的顺序调用。