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);
         }
     });
 }

 

 

posted @ 2010-08-03 21:58  NcuChenMeng  阅读(157)  评论(0编辑  收藏  举报