我通常爲自己弄清楚事情,但這一次給了我一個非常困難的時間。我需要在點擊一個數據庫後,改變由php創建的表中的按鈕的文本值。如何更改ajax成功函數中單擊事件處理程序中的按鈕的文本
<td id="order_num"><?php echo $order -> order_num; ?></td>
<td><?php echo $order -> data; ?></td>
<td><?php echo $order -> data; ?></td>
<td><?php echo $order -> data; ?></td>
<td><?php echo $order -> data; ?></td>
<td><?php echo $order -> data; ?></td>
<td><?php echo $order -> data; ?></td>
<td><?php echo $order -> data; ?></td>
<!-- **** this is the button. ******** -->
<td><button type="submit" class="accept_order" id ="row_<?php echo $order -> order_num; ?>"
data-row_id = "row_<?php echo $order -> order_num; ?>" data-current_user = "<?php echo $user_id; ?>"
data-order_num = "<?php echo $order -> order_num; ?>">Accept</button>
這裏是一個Ajax調用
$(文件)。就緒(函數(){ $( '店 ')的大混亂。在(' 點擊' ,「按鈕」,功能(E){
var button = $(this).find('button'); //trying to put the value of the current button in a variable to pass to the ajax function.
var current_user = $(this).closest('.shop').find('.accept_order').data('current_user');
console.log(current_user);
var row_id = $(this).closest('.shop').find('.accept_order').data('row_id');
var accepted_order = $(this).closest('.shop').find('.accept_order').data('order_num');
console.log(accepted_order);
e.preventDefault();
$.ajax('url', {
type: "POST",
data: { order_id: accepted_order, user_id: current_user },
success: function(msg){
console.log(msg);
console.log(this);
//change the text of the button to something like "accepted"
***************this is where I have problems ***********************
$(this).html('accepted'); or
$(this).closest('.shop').find('button').html(msg); or
button.text(msg);
},
error: function(){
$(this).closest('.shop').find('.accept_order').html("failure");
}
});
});
});
</script>
我確實使用了$(「按鈕」)HTML(MSG); 但改變了所有的按鈕好像我失去範圍的OB當成功功能內部的時候。任何想法或幫助將不勝感激。提前致謝。
你是個天才,非常感謝。我一直在爲此工作數天。我有一種感覺,「這個」是不同的。 – user3384868
我很高興你解決你的問題:) – Ahmedmoawad