我正在使用以下Ajax函数发送请求。虽然有些奇怪的事情发生。请求完成后,返回的新按钮不会启用ajax。它充当了一个正常的锚点。完成ajax请求后,Ajax achor变为正常的锚!
$(document).ready(function() {
$(".UIButton a").click(function(e) {
e.preventDefault();
if (! $(this).data("isClicked"))
{
var requestData = $(this).attr("href");
var link = $(this);
$.ajax({
context: this,
dataType: 'js',
url: requestData,
beforeSend: function() {
$(link).fadeOut("slow");
},
error: function() {
},
success: function(response) {
$(link).parent().html(response);
$(link).stop().fadeIn("slow");
}
});
// Toggle isClicked to prevent button mashing
link.data("isClicked", true);
// Create timeout to restore button
setTimeout(function() { link.removeData("isClicked") }, 1000);
}
});
});
下面是来自服务器,这是正确的回: <a class="delete" href="https://stackoverflow.com/users/delete/3333">Delete</a>
原来这里是按钮:
<div class="UIButton">
<a class="Add" href="https://stackoverflow.com/users/add/3333">Add</a>
</div>