开发者

Rails 3 loading page with ajax animation

i have already read this topix : "http://stackoverflow.com/questions/4820637/how-do-i-perform-an-ajax-request-to-the-create-action-on-loading-a-page-in-rails" but it doesn't respond to the question..

I want to make a loading animation into my rails 3 app cause the server takes time to send email and do some other calculation so the user experience is not so g开发者_StackOverflowood...

I have read this tutorial : http://www.marketingformavens.com/blog/create-a-page-loading-animation-with-ruby-on-rails-and-ajax but it's for rails2 (remote_function doesn't exist anymore in rails 3).

I wonder if someone can tell the way i should do so : -> having a nice animation loaded onto the screen when the user click on an action (like create, or update)

Thank's a lot.

Hope to find a answer...


If I understand you want to load an animation while your action is done in ajax. Just use the jQuery API to call your controller actions in Ajax and use callbacks to stop your animations :

    $("#myaction").click(function(){
      //write your animation code here

      $.ajax({
        url: "http://localhost:3000/yourcontrolleraction",
        dataType: "json",
        type: "POST",
        processData: false,
        contentType: "application/json",
        data: yourdata
        success: function(){
             //stop your animation here
        }
      })
    });

For more on using jQuery Ajax with Rails I suggest your read this excellent post : http://blog.project-sierra.de/archives/1788

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜