2010-09-22 77 views
-1

有一個調試syntax錯誤,但我看不到它!即時通訊有點新手,所以請原諒我的代碼!這個jQuery有什麼問題?

$(document).ready(function(){ 
    /* fetch elements and stop form event */ 
    $("form.follow-form").submit(function (e) { 
     /* stop event */ 
     e.preventDefault(); 
     /* "on request" */ 
     $(this).find('i').addClass('active'); 
     /* send ajax request */ 
      $.ajax({ 
       type: "POST", 
       url: "ajax_more.php", 
       data: $(this).serialize(), 
       cache: false, 
       success: function(html){ 
        $("ul.statuses").append(html); 
        $("form.follow-form").remove(); 
       } 
      }); 
      else { 
       $(".morebox").html('The End'); 
      } 
      return false; 
    }); 
}); 
+0

哪來的,如果在別的嗎? – Pharabus 2010-09-22 13:25:00

+1

和'else'部分是什麼? – 2010-09-22 13:25:41

+0

netbeans語法錯誤,顯示紅線!並且請有禮貌,不需要厚顏無恥?你沒有義務回答這個問題!謝謝 – getaway 2010-09-22 13:25:42

回答

2

試試這個

$(document).ready(function() { 
    /* fetch elements and stop form event */ 
    $("form.follow-form").submit(function(e) { /* stop event */ 
     e.preventDefault(); /* "on request" */ 
     $(this).find('i').addClass('active'); /* send ajax request */ 
     $.ajax({ 
      type: "POST", 
      url: "ajax_more.php", 
      data: $(this).serialize(), 
      cache: false, 
      success: function(html) { 
       $("ul.statuses").append(html); 
       $("form.follow-form").remove(); 
      } 
     }); 
     $(".morebox").html('The End'); 
     return false; 
    }); 
});​ 
+0

這對我很有用!,很好! :)) – getaway 2010-09-22 14:14:31

+0

歡迎你,高興地看到你快樂:) – 2010-09-22 14:18:38

10

你有一個else,但沒有if

下面是帶有一些正確縮進的代碼 - 縮進使得代碼更容易理解,因此您可以更快地發現錯誤。

$(document).ready(function(){ 

    /* fetch elements and stop form event */ 
    $("form.follow-form").submit(function (e) { 

     /* stop event */ 
     e.preventDefault(); 

     /* "on request" */ 
     $(this).find('i').addClass('active'); 

     /* send ajax request */ 
     $.ajax({ 
      type: "POST", 
      url: "ajax_more.php", 
      data: $(this).serialize(), 
      cache: false, 
      success: function(html){ 
       $("ul.statuses").append(html); 
       $("form.follow-form").remove(); 
      } 
     }); 


======> /* HERE’S THE ELSE WITHOUT AN IF */ 

     else { 
      $(".morebox").html('The End'); 
     } 

     return false; 
    }); 

});