ajax and rjs

Post on 18-May-2015

4.232 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Brief overview of using Ajax with PrototypeJS and RubyOnRails' RJS.

TRANSCRIPT

Ajax and RJS

Yes, Macs Rule

Ajax

• mini web request from javascript

• used to update pieces of content in page

When NOT to use AJAX

• when the action is related to navigation

• when there is another AJAX call inside that action (will get very complicated)

Cons of AJAX

• can slow down a page just as easy as speed up a page

• explosion of partials

Pros of AJAX

• when done well, it will make the user experience much better

• saves server traffic and potentially load

• and...

It’s cool.

How does it work?Something like this:

You always need a library.

Using PrototypeJS

new Ajax.Updater('my_div', '/items'); text, partial or template from server

new Ajax.Request('/items')

javascript from server

Ruby Java ScriptController:

RJS template:

JS Generating Methods• page is the virtual page object where you

can write javascript to.

Inline RJS

• no template

• in the controller

Rails’ Helpers

Using a Spinner

• link_to_remote_submit already has a spinner.

• put a spinner onclick, not on the callbacks

• disable the spinner onComplete or on content update

spin_div

Spinner is created in the container and gets reset when container gets updated.

Status Notice JS

Alternative and Related Techniques

JSON

Cross-Server JS

Comet, AJAX' big brothersynchronous VS asynchronous

<%= periodically_call_remote %> sucks

push javascript from server, using a flash socket

copyleft dominiek.com

top related