ajax and rjs

21
Ajax and RJS

Upload: dominiek-ter-heide

Post on 18-May-2015

4.232 views

Category:

Technology


2 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Ajax and RJS

Ajax and RJS

Page 2: Ajax and RJS

Yes, Macs Rule

Page 3: Ajax and RJS

Ajax

• mini web request from javascript

• used to update pieces of content in page

Page 4: Ajax and RJS

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)

Page 5: Ajax and RJS

Cons of AJAX

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

• explosion of partials

Page 6: Ajax and RJS

Pros of AJAX

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

• saves server traffic and potentially load

• and...

Page 7: Ajax and RJS

It’s cool.

Page 8: Ajax and RJS

How does it work?Something like this:

You always need a library.

Page 9: Ajax and RJS

Using PrototypeJS

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

new Ajax.Request('/items')

javascript from server

Page 10: Ajax and RJS

Ruby Java ScriptController:

RJS template:

Page 11: Ajax and RJS

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

can write javascript to.

Page 12: Ajax and RJS

Inline RJS

• no template

• in the controller

Page 13: Ajax and RJS

Rails’ Helpers

Page 14: Ajax and RJS

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

Page 15: Ajax and RJS

spin_div

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

Page 16: Ajax and RJS

Status Notice JS

Page 17: Ajax and RJS

Alternative and Related Techniques

Page 18: Ajax and RJS

JSON

Page 19: Ajax and RJS

Cross-Server JS

Page 20: Ajax and RJS

Comet, AJAX' big brothersynchronous VS asynchronous

<%= periodically_call_remote %> sucks

push javascript from server, using a flash socket

Page 21: Ajax and RJS

copyleft dominiek.com