2011-06-03 25 views
0

好嗎更新按鈕值,這裏的情況:的jQuery活不上成功

<div> 
<a href=".." id=".."></a> //similarly multiple links 
</div> 

當用戶點擊任何鏈接,它的id是由一個AJAX請求GET變量傳遞。一旦成功,另一個<div>得到充滿了一些其上寫有一些值的按鈕列表。當用戶點擊按鈕時,他可以通過在警告框中輸入新值來更改寫在按鈕上的值。這也是由AJAX請求完成的。但是,成功後,值會在數據庫中更新,但已更改的值不會寫回按鈕。

$('#tags a').click(function(e){ 
e.preventDefault(); 
var send = $(this).attr('href'); 
$.ajax({ 
    url:'getitemsfortag.php', 
    data:{tag:send}, 
    type:'GET', 
    dataType:'html', 
    success:function(data){ 
     $('#items').empty().append(data); //data contains list of buttons 
    }, 
    error:function(xhr, status){ 
     alert("Problem"); 
    } 
}); 

}); 

$("input[type='button']").live('click',function(){ 
var selected = $(this).attr("id"); 
var val = prompt("Enter new value",0); 
$this = $(this); 
$.ajax({ 
    url:'updateCostItems.php', 
    data:{toupdate:selected, updatewith:val}, 
    type:'GET', 
    dataType:'json', 
    success:function(json){ 
     $this.val(json.update); 
    }, 
    error:function(xhr, status){ 
     alert("Problem"); 
    } 
    }); 
}); 
}); 

有關如何獲取更改值寫回按鈕的任何建議?

回答

1
$this.html(json.update); 

代替

$(this).val(json.update); 
+0

@devmatt:羅.. – 2011-06-03 12:06:28

+0

什麼,當你這樣做會發生什麼? – devmatt 2011-06-03 12:10:07

+0

@devmatt沒有什麼..只是像以前一樣.. – 2011-06-03 12:12:17