我正在尝试使用 ajax 在 beforeSend 中淡入背景色并成功淡出背景色。我不知道我做错了什么。请帮忙。
var data={
action: 'tag_user_update',
postSearchNonce : MyAjaxSearch.postSearchNonce,
tag : $(this).closest("a").text(),
users_id : $("#users_id").val()
}
$.ajax({
url: MyAjaxSearch.ajaxurl,
type:'POST',
cache: false,
data:data,
beforeSend: function() {
$('.tag_link').animate({ backgroundColor:'yellow'},'slow');
},
success: function(data){
$('.tag_link').animate({ backgroundColor:'white'},'slow');
}
});//ajax
最佳答案
确保您的 ajax 方法遵循此结构 $.ajax({}).done({}) 或 $.ajax({}).success({})。您已将回调函数 .success() 包含在 .ajax({}) 请求中。
正如您在下面的示例中看到的,.done() 不包含在 .ajax() 调用中。 .success() 也不应该是内部的。 done() 和 .success() 都是在您的 ajax() 请求之后发生的回调函数。此外,.success() 已被弃用,因此 .done() 在下面的示例中具有相同的效果
来自 http://api.jquery.com/jquery.ajax/
$.ajax({
url: "http://fiddle.jshell.net/favicon.png",
beforeSend: function( xhr ) {
xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
}
})
.done(function( data ) {
if ( console && console.log ) {
console.log( "Sample of data:", data.slice( 0, 100 ) );
}
});
关于javascript - 我正在尝试使用 jquery ajax 淡入和淡出 css 背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30065514/