2011-05-18 76 views
1

我遇到我的更新按钮和jquery ajax的问题​​。现在,当我点击我的更新按钮时,它将任何更新的数据保存到数据库中。我的目标是如果更新成功,我想滑动消息。我在看ajax文章,并且使用成功事件看起来好像会起作用,但我不知道如何合并它。我将如何做到这一点?会是这样的吗?帮助jquery 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); 
        } 
       }); 
     }); 
    }); 
+0

什么是服务器语言? – 2011-05-18 14:46:01

+0

为什么这么复杂?为了您的第一次尝试,您应该使用一个简单的警报框。如果它可以工作,创建一个简单的div,隐藏的默认可见性。在成功事件中,您切换此对象(使用.show()) – reporter 2011-05-18 14:50:44

+0

我目前正在使用vb – bolo 2011-05-18 15:00:31

回答

0

查看这个question关于如何处理成功事件的例子。希望这可以帮助!

0
$("#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失败和其他成功的

+0

typo $(“#form”)=> $(“#form”);) – stecb 2011-05-18 14:48:35

+0

yup,now fixed,thanks :) – Sourav 2011-05-18 14:50:04

0

在jQuery的功能后,就可以执行一些回调函数。

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. 
    } 

http://docs.jquery.com/Post

0

至少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()或什么的东西叫一些东西。

只是wrote a blog post on it myself,如果你有兴趣阅读更多。