jQuery study Notes (三):Ajax
1. Ajax
Ajax请求:
$.ajax({
url: 'myPage.php',
success: function(response) {
alert(response);
},
error: function(xhr) {
alert('Error! Status = ' + xhr.status);
}
});
根据Ajax请求结果更新元素:
function updateStatus() {
$.ajax({
url: 'getStatus.php',
success: function(response) {
// update status element
$('#status').html(response);
}
});
}
从Ajax调用返回服务器Response
//...
getUrlStatus('getStatus.php', function(status) {
alert(status);
});
// ...
function getUrlStatus(url, callback) {
$.ajax({
url: url,
complete: function(xhr) {
callback(xhr.status);
}
});
}
浙公网安备 33010602011771号