Top Banner
Section led by Ivan Lee Reachable at ivan period lee at cs period stanford period edu 1
7

Ajax

Feb 14, 2016

Download

Documents

Milla

Ajax. Section led by Ivan Lee. Reachable at ivan period lee at cs period stanford period edu. Basic AJAX Flow. User types a character Javascript invoked (hint: use a JS class) Create and set a function that will be called when an HTTP status 200 is returned - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ajax

Section led by Ivan Lee

Reachable at ivan period lee at cs period stanford period edu

1

Page 2: Ajax

- User types a character- Javascript invoked (hint: use a JS class)

- Create and set a function that will be called when an HTTP status 200 is returned

- Construct a POST url to a specific method of a Rails controller, incorporating any necessary parameters

- Send the xmlhttp request

2

Page 3: Ajax

- Rails method invoked- Perform any database queries that need

to be done server-side- Render a partial – this creates full HTML,

which is treated as the xmlhttp response!

- What happens if you return a JSON object instead?

- Set the innerhtml of the appropriate object

3

Page 4: Ajax

if (window.XMLHttpRequest) { this.xmlhttp = new XMLHttpRequest(); }

this.xmlhttp.onreadystatechange = function()…

this.xmlhttp.open(sMethod, sUrl) this.xmlhttp.setRequestHeader(sName,

sValue) this.xmlhttp.send(varBody) this.xmlhttp.responseText4

Page 5: Ajax

Make sure you think about how to make your classes and AJAX code reusable

Make sure you pass along an authenticity token! (see assignment hints section)

Encode your parameters (see assignment hints section)

Make sure thumbnails redirect to the appropriate link. If the user has a large photo collection, make sure that the selected photo is visible.

No using any other JS frameworks, or built-in Rails Ajax Helpers

Test in Firefox Validate your HTML

5

Page 6: Ajax

This is the last project!If you want to strut your stuff, this is the time to do it. You have all these tools at your disposal.

6

Page 7: Ajax

7