2012-05-30 109 views
0

我已經發出了jQuery的Ajax請求,它的反應是真實的一個Ajax請求沒有成功的響應後,會發生

,但我需要更改頁面上的所選項目的價值,但無論是動作發生也不是警報的警報

,如:

$('#rename').click(function() { 
//alert($(this).closest('td').prev().prev().text()); 
var name = prompt('enter the new name'); 
if (name) $.ajax({ 
    url: url() + '/rename', 
    type: 'POST', 
    data: { value: name, 
     id: $(this).closest('tr').find('td :first').attr('value') 
    }, 
    success: function (result) { 
     if (result.content == 1) { 
      //location.reload(); 
      alert(name); 
      //$(this).closest('td').prev().prev().text(name); 
     } 
    } 
}) 
}) 

你怎麼想克服這個問題?

回答

0

這應該幫助您解決問題

$('#rename').click(function() { 
    //alert($(this).closest('td').prev().prev().text()); 
    var name = prompt('enter the new name'); 
    if (name) $.ajax({ 
     url: url() + '/rename', 
     type: 'POST', 
     data: { value: name, 
      id: $(this).closest('tr').find('td :first').attr('value') 
     }, 
     success: function (result) { 
      alert('success'); 
      if (result.content == 1) {//location.reload(); 
       alert(name); 
       //$(this).closest('td').prev().prev().text(name); 
      } 
     }, 
     error: function() { 
      alert('error'); 
     } 
    }) 
}); 

基本上都添加了一對夫婦的額外加分。

  1. 你怎麼知道的成功正在發生,只是result.context不等於1,所以增加了alert('success');
  2. 你怎麼知道它的成功resturning在所有?添加

    錯誤:function(){ alert('error'); }

  3. 您最後錯過了;。 :)

+0

從螢火它與1響應和值在數據庫 改變,我想 提醒現在的成功 –

+0

現在工作得很好,但這一行動不工作是不可能或做什麼$ (本).closest( 'TD')分組()先前()HTML(名稱)。。。; –

+0

認爲你需要打開另一個問題我的朋友! – Liam