async

16
Asynchronize with jQuery Kevin Griffin

Upload: kevin-griffin

Post on 08-May-2015

1.183 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Async

Asynchronize with jQueryKevin Griffin

Page 2: Async

Developer for Antech Systems Chesapeake, VA

Microsoft MVP – Client App Dev ASPInsider Leader of Hampton Roads .NET Users Group

About Me

Page 3: Async

What is AJAX? Basic AJAX Implementation AJAX Shortcuts Global Handlers Design Considerations

Agenda

Page 4: Async

Buzzword Asynchronous JavaScript and Xml

Allows us to load or post data from the server without having to do post back.

AJAX?

Page 5: Async

Asynchronous ◦ Don’t block the current thread◦ No defined execution time

Start a call, and designate a callback method for when the call returns.

Designing AJAX Applications

Page 6: Async

FireBug◦ http://getfirebug.com/

Fiddler◦ http://www.fiddler2.com/

AJAX Toolkit◦ Psych!

Tools for an AJAX Developer

Page 7: Async

Low level interface for making AJAX calls.

Prototype:◦ $.ajax(settings)

jQuery.ajax()

Page 8: Async

url◦ Url that jQuery should use for making the request.

dataType◦ The type of data we’re expecting from the response.◦ Xml, JSON, Script, Html

success◦ Function to call if the AJAX call succeeds.

error◦ Function to call if the AJAX call fails.

complete◦ Function to call when the AJAX call returns. Success or

Failure.

Basic Settings

Page 9: Async

DemoBasic use of $.ajax()

Page 10: Async

Because developers are lazy.

$.get() $.getJSON() $.getScript() $.post() $.load()

FAILS SILENTLY!

Shortcuts

Page 11: Async

DemoLet’s take a shortcut

Page 12: Async

Keep track of AJAX events globally in your applications.

$(element).ajaxComplete() $(element).ajaxError() $(element).ajaxSend() $(element).ajaxStart() $(element).ajaxStop() $(element).ajaxSuccess()

Global Handlers

Page 13: Async

DemoImplementing Global Event Handlers

Page 14: Async

Let the user know something is happening◦ Progress indicators◦ Loading dialogs

Handle errors gracefully◦ Either local or global handlers

Plan for worst case scenarios◦ Dial up, hotel wireless

SEO Back Button

Design Considerations

Page 15: Async

DemoPutting It All Together

Page 16: Async

Email: [email protected] Twitter: 1kevgriff

http://www.kevgriffin.com

Contact Me