2014-04-02 70 views
-1

我已經寫了一個函數的ajax調用來點擊圖像時觸發。在php頁面中,圖像使用php gd旋轉。不知何故,阿賈克斯沒有被觸發。我無法弄清楚我在犯什麼錯誤!這個Ajax調用有什麼問題?

JQuery的:

$(document).ready(function() { 
     $("#rotate-head-1").click(function(){ 
      alert("Function running"); 

      var filename = document.getElementById('image-1').getAttribute('src'); 
      $.ajax({ 
       url:"test.php", 
       type:"GET", 
       async:true, 
       data:{procedure:"rotate",file_name:filename}, 
       cache:false 
       success: function(data) { 
        alert("Success"); 
       } 
       error: function() { 
        alert("Failure"); 
       } 
      }); 

     }); 
    }); 

HTML:

<img id="rotate-head-1" src="rotate_icon.jpg" width="20" height="20" border="0" alt="Rotate Image" title="Rotate Image"> 
<img id="image-1" src="../../member_media/media/test.jpeg" width="200" border="0"> 

任何幫助或建議,將不勝感激。

+0

控制檯中的任何錯誤? – laaposto

+0

那麼整個點擊處理程序沒有被觸發?或者它只是ajax呼叫? – gpgekko

+0

當我刪除$ .ajax({..中的所有內容,然後「函數運行」警報正在工作,但是當我把它放在這裏時,沒有任何工作(包括那個警報) – programmer

回答

7

我看到的是你的cachesuccess選項後缺少逗號。這些錯誤應該在控制檯中出現,您可以使用它來即時調試這些類型的問題。

$(document).ready(function() { 
    $("#rotate-head-1").click(function(){ 
     alert("Function running"); 

     var filename = document.getElementById('image-1').getAttribute('src'); 
     $.ajax({ 
      url:"test.php", 
      type:"GET", 
      async:true, 
      data:{procedure:"rotate",file_name:filename}, 
      cache:false //<-- you miss a comma here? 
      success: function(data) { 
       alert("Success"); 
      } // <-- and miss a comma here 
      error: function() { 
       alert("Failure"); 
      } 
     }); 

    }); 
}); 
+0

它解決了這個問題,非常感謝。 – programmer