jQuery live不会在成功时更新按钮值

时间:2011-06-03 11:49:18

标签: jquery ajax

好的,情况如下:

<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 个答案:

答案 0 :(得分:1)

$this.html(json.update);

而不是

$(this).val(json.update);
相关问题