2014-06-05 28 views
2

嘗試讓此AJAX請求生效。任何身體部分都隱藏起來,就像事件處理程序要做的第一行一樣。但是,about.html中的內容不會加載,因此我不會收到錯誤消息。有任何想法嗎?無法獲得基本的AJAX腳本,只能使用jQuery和Javascript。

$(document).ready(function() { 


     //AJAX About.html 
     $('#about-button').on('click', function() { 
     $('body section').hide(), 

     $.ajax('about.html'), { 
      success: function(response) { 
      $('.about-page').html(response).slideDown() 
      }, 
      error: function(request, errorType, errorMessage) { 
      $('body').html("<p> 'Error: ' + errorType + ' with message ' + errorMessage </p>") 
      }, 
      timeout: 3000 
     }; 
     }); 



    }); 

回答

2

您的語法不正確。您提前關閉$.ajax()的參數,因此不會將對象傳遞給它。

取而代之的是:

$.ajax('about.html'), { 
     success: function(response) { 
     $('.about-page').html(response).slideDown() 
     }, 
     error: function(request, errorType, errorMessage) { 
     $('body').html("<p> 'Error: ' + errorType + ' with message ' + errorMessage </p>") 
     }, 
     timeout: 3000 
    }; 

您需要這所以選擇實際上是傳遞給$.ajax()作爲第二個參數對象:

$.ajax('about.html', { 
     success: function(response) { 
     $('.about-page').html(response).slideDown(); 
     }, 
     error: function(request, errorType, errorMessage) { 
     $('body').html("<p> 'Error: ' + errorType + ' with message ' + errorMessage </p>"); 
     }, 
     timeout: 3000 
    }); 
+0

謝謝您的幫助! – user3709721

+0

謝謝@ jfriend00! – user3709721