如果ajax失敗,我想返回我的按鈕值。
這HTML(PHP的):
<a href="javascript:void(0);" id="follow-topic" value="7">
<button class="btn btn-xs btn-primary pull-right"><?php echo $_LANGS['forum']['follow']; ?></button>
</a>
這個js(在PHP):
$("#follow-topic").click(function(event) {
var topicid = $(this).attr('value');
var button_follow_html = $(this).html();
if ($(this).is("a[disabled]")){ return false; }
$("#follow-topic button").html('<?php echo $_LANGS['system']['loading_button']; ?>');
$(this).attr({ disabled: true});
$.ajax({
url: "",
data: { follow_topic: topicid },
type: "POST",
success: function (data) {
$("#follow-topic").html(data);
$("#follow-topic").attr({ disabled: false});
},
error: function(data, button_follow_html) {
handleRequestError(data);
$("#follow-topic").attr({ disabled: false});
$("#follow-topic").html(button_follow_html);
}
});
});
我已經更改按鈕值$_LANGS['system']['loading_button']
但我想回到$_LANGS['forum']['follow']
如果阿賈克斯失敗或客戶端丟失連接。
該系統使用多種語言,如果ajax成功,按鈕將被替換爲後面的按鈕,所以我不能使用$("#follow-topic button").html('<?php echo $_LANGS['forum']['follow']; ?>');
。
對不起,我的英語,謝謝