2012-08-02 113 views
3
$.ajax({ 
    url: "captcheck.php", 
    type: "GET", 
    data: "code="+captcha.val(),   
    cache: false, 
    success: function (html) {    
     if (html==1) { 
      captcha.removeClass('validation-error',animateSpeed); 
      return true; 
     } 
     else { 
      captcha.addClass('validation-error',animateSpeed); 
      return false; 
     }  
    },  
    error: function(httpRequest, textStatus, errorThrown) { 
     alert("status=" + textStatus + ",error=" + errorThrown); 
    } 
}); 

現在,這是一個非常簡單的Ajax功能,但也不是其成功獲取調用,也不錯誤,我查了XHR與響應的螢火蟲和完善,仍沒有成功或錯誤被調用。任何人都可以幫忙嗎?

回答

0

也許這是if (html==1)因爲成功回調返回的字符串,你應該嘗試if (html==="1")

2

有沒有辦法,我可以在我結束測試你的代碼,但我會給我的兩分錢:

  • 添加'complete'回調函數以幫助您確定代碼中是否存在任何語法錯誤。從jQuery文檔:''Complete'是一個函數,當請求結束時(在執行成功和錯誤回調之後) 「

  • 使用諸如alert('str')console.log('str')之類的簡單代碼進行調試。

順便說一句,做addClassremoveClass支持不止一個參數的更多?我無法在official document中找到它。