2012-11-09 79 views
0

我已經寫了下面的代碼使用jQuery進行Ajax調用:阿賈克斯jQuery的不工作

$.ajax({ 
    url: 'verify.php', 
    type: 'POST', 
    data: { 
     'mobile': 'update' 

    } 
    success: function(response) { 
     if (response == 'success') { 
      $('#popupscreen').fadeOut('slow'); 
     } 
     else { 
      $("#error").html("<p>" + Registration failed! Please try again. + "</p>").show(); 
     } 
    } 
}); 

我收到錯誤未捕獲的SyntaxError:意外的標識符合成功:函數(響應){ 爲什麼我得到這個錯誤?

+3

'$(「#error」)。html(「

註冊失敗!請重試

「).show();' – undefined

+0

如果您的問題中的初始代碼格式與您在IDE中的格式相同,那麼您應該考慮學習一些代碼格式規則,它會幫助您(和其他人)閱讀你自己的代碼很多 –

回答

4

你缺少一個逗號:

type : 'POST', 
data : { 
    'mobile' : 'update' 

}, //<---- there should be a comma here 
success : function(response){ 
    if(response == 'success') 
    { 

也有一些報價:

$("#error").html("<p>Registration failed!Please try again.</p>").show(); 
5

因爲您在數據的右大括號後缺少逗號。

你的代碼應該看起來更像是這樣的:

$.ajax({ 
    url: 'verify.php', 
    type: 'POST', 
    data: {'mobile': 'update'}, 
    success: function(response) { 
     if (response == 'success') { 
      $('#popupscreen').fadeOut('slow'); 
     } 
     else { 
      $("#error").html("<p>" + 'Registration failed!Please try again.' + "</p>").show(); 
     } 
    } 
}); 
+0

感謝Mike和@undefined。有兩個錯誤。 – Pooja

0

你缺少一個逗號權在您的「成功」之前:

data : { 
     'mobile' : 'update' 
    },