[英]help with jquery ajax success event
我的更新按鈕和jquery ajax出現問題。 現在,當我單擊更新按鈕時,它將任何更新的數據保存到數據庫中。 我的目標是,如果更新成功,我想向上滑動一條消息。 我正在查看ajax帖子,並使用成功事件似乎可以正常工作,但我不知道該如何配合。 我該怎么做? 會是這樣嗎?
$(document).ready(function(){
$('#divSuccess').hide();
$('#btnUpdate').click( function() {
alert('button click');
$.ajax({
url: "test.aspx",
context: document.body,
success: function(){
$('#divSuccess').show("slide", { direction: "down" }, 3000);
$('#divSuccess').hide("slide", { direction: "down"}, 5000);
}
});
});
});
請查看此問題 ,以獲取有關如何處理成功事件的示例。 希望這可以幫助!
$("#targetDiv").load("page.php",$("#form").serializeArray(),function (response)
{
if (response == '0' && response != '')
alert('Request not sent to server !\n');
else if(response == '-1')
alert('Please write some more !\n');
else
{
alert("success! ");
}
}
);
我已經為錯誤0和-1回聲,為成功而其他
在jquery post函數中,您可以執行一些回調函數。
function (data, textStatus) {
// data could be xmlDoc, jsonObj, html, text, etc...
this; // the options for this ajax request
// textStatus can be one of:
// "timeout"
// "error"
// "notmodified"
// "success"
// "parsererror"
// NOTE: Apparently, only "success" is returned when you make
// an Ajax call in this way. Other errors silently fail.
// See above note about using $.ajax.
}
至少使用jQuery 1.5,您已經有了AJAX事件的延遲對象和新語法(包括success
)。
var $ajaxcall = $.ajax({
url : 'myurl.svc/somemethod',
data : '{ somedata : "sometext" }'
});
$ajaxcall.success(function() {
// do something on successful AJAX completion
});
當然,您也可以將其鏈接起來,然后按照$.ajax().success()
調用某些內容。
如果您有興趣閱讀更多內容,請自己寫一篇博客文章 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.