2015-06-07 75 views
-3

我有我的安排AJAX腳本非常好辛苦,我想,如果我能幫助一些幫助這裏語法錯誤在AJAX腳本

$(document).ready(function() { 
     $follow_container = $('#follow_container'); 
     var follow = localStorage.getItem('follow'); 
     if (follow !== null) { 
     $follow_container.html(follow).show() 
     } 
     $('.followclick').on('click', function(event) { 
      if (follow == null) { 
       $('#follow_container').load('http://mysite/news.asp', function() { 
        localStorage.setItem('follow', $follow_container.html()); 
       } 
       }); 
+0

什麼是你的代碼錯誤?什麼不起作用? – David

+0

你是什麼意思*安排我的ajax *?請詳細說明併發布適當的代碼 – Dhiraj

+0

它會告訴我腳本的按鈕處的語法錯誤。 – neiza

回答

0

每次打開一個代碼塊的時間(使用{ ),你也必須關閉它。每當您打開一個函數調用(使用()時,您也必須關閉它。你只是編寫代碼而不實際關閉任何東西。

當你這樣做:

if (follow == null) { 

某處,在後面的代碼,在那if塊的最後,你需要做的是:

} 

當你這樣做:

on(

某處,稍後,您需要執行此操作:

) 

所以,把所有的一起......閉上你的代碼塊:

$(document).ready(function() { 
    $follow_container = $('#follow_container'); 
    var follow = localStorage.getItem('follow'); 
    if (follow !== null) { 
     $follow_container.html(follow).show() 
    } 
    $('.followclick').on('click', function(event) { 
     if (follow == null) { 
      $('#follow_container').load('http://mysite/news.asp', function() { 
       localStorage.setItem('follow', $follow_container.html()); 
      }); 
     } 
    }); 
});