SlideShare a Scribd company logo
welcome
who am i? kyle simpson @getify [email_address] http://getify.com
what is the meaning of life? i dunno. maybe jQuery? or 42. something like that.
so, why are we here? I’m glad you asked.
extending ajax events for all mankind… jQuery Conf 2009
our little chat today what are Ajax events? how does jQuery handle Ajax events? why would I want to extend them? gimme some real code! mpAjax flXHRproxy
 
what are Ajax events? events specifically triggered when Ajax requests happen. duh. $([‘Complete’,’Error’,’Send’,’Start’,’Stop’,’Success’]).each(function() { console.log(‘ajax’ + this); }); technically, an event is a signal to jQuery to call one or more registered callback functions to let them know something happened. blah, blah, blah.
how does jQuery handle Ajax events? “ a tale of two cities” per-request (aka, “local”) callback functions  as parameters/options to $.ajax(), $.get(), $.post(), etc global events listeners bound to DOM element(s) triggered with every Ajax call
how does jQuery handle Ajax events? per-request callbacks: ‘ beforeSend’, ‘complete’, ‘error’, ‘success’, ‘timeout’ different function signatures (parameters) only one registered callback per event per request
how does jQuery handle Ajax events? global events: “ ajax___” where ___ is one of: ‘Complete’,’Error’,’Send’,’Start’,’Stop’,’Success’ can be bound to whatever DOM element(s) you choose; all handlers get called for each event ‘ Start’ and ‘Stop’ are special consistent function signature can be disabled per-request via ‘global:false’
… try to take over the Ajax event.
how does jQuery handle Ajax events? so, how can we use them? hide/show loading “spinner” show generic error message resubmit a request on timeout
how does jQuery handle Ajax events? hide/show loading “spinner”:
how does jQuery handle Ajax events? show generic error message:
how does jQuery handle Ajax events? resubmit a request on timeout:
why would I want to extend them? overall goal == better code organization existing events not granular enough monolithic callback functions with ‘switch’ extend (or override) existing functionality change callback signature additional pre- or post-processing on requests or responses
why would I want to extend them? some extension ideas: request retry on timeout “ application error” event handling smarter response caching ordered responses via request/response queue solve “travelling salesman” problem
gimme some real code! example: application-level success/error
gimme some real code! example: application-level success/error
mpAjax multi-part Ajax *responses* --  return multiple different "parts" of data (different types, etc) in a single response. return a block of HTML (without encoding/escaping it into JSON), and a separate JSON packet with data return an HTML template and some JSON data separately, without any obfuscation/encoding/escaping of either return some HTML, some JSON, and also some CSS, and handle all three types of data separately return two or more different blocks of HTML, and need to handle each separately
mpAjax strategy: post-process data from a ‘success’ful Ajax request if multi-part format found, string parse response text, send each part to separate response handler otherwise, behave exactly like normal Ajax request/response
mpAjax mpAjax jQuery plugin:  http://plugins.jquery.com/project/mpAjax code:  http://plugins.jquery.com/files/jquery.mpAjax.js_6.txt demo:  http://test.getify.com/mpAjax
flXHRproxy flXHR is a javascript API wrapper that mimics native XHR object in almost every way, but behind the scenes, makes calls via an invisible flash asset (crossdomain.xml) flXHRproxy adapts jQuery to use flXHR for fully featured cross-domain Ajax uses the jQuery plugin ‘XHR’ to register flXHR as a XHR clone registers/associates specific flXHR config options with a specific target URL
flXHRproxy strategy: register flXHR as XHR drop-in replacement extend ‘success’ function signature (parameters) to include the XHR object tie flXHR’s ‘onerror’ event to trigger the jQuery ‘error’ events
flXHRproxy flXHR:  http://flxhr.flensed.com flXHRproxy jQuery plugin:  http://plugins.jquery.com/search/node/fxhr code:  http://plugins.jquery.com/files/jquery.flXHRproxy.js_3.txt demo:  http://flxhr.flensed.com/code/tests/flxhr-7e.html
enjoy http://plugins.jquery.com/project/mpAjax http://test.getify.com/mpAjax http://plugins.jquery.com/project/flXHR http://flxhr.flensed.com/jquery.php rate this talk:  http://speakerrate.com/talks/1408-extending-ajax-events-for-all-mankind

More Related Content

PDF
Thomas Fuchs Presentation
PDF
The evolution of asynchronous javascript
PPT
Direct Web Remoting : DWR
PPT
mukesh
PDF
JavaScript Best Pratices
PDF
Avoiding callback hell with promises
PPTX
Being a pimp without silverlight
PPT
Ajax
Thomas Fuchs Presentation
The evolution of asynchronous javascript
Direct Web Remoting : DWR
mukesh
JavaScript Best Pratices
Avoiding callback hell with promises
Being a pimp without silverlight
Ajax

What's hot (19)

PDF
Présentation de HomeKit
PDF
ReactJS
ODP
Step objects
PPTX
Good karma: UX Patterns and Unit Testing in Angular with Karma
PPT
Javascript
PDF
React.js enlightenment
PPTX
Console in javaScript
PDF
Ajax
PPTX
Introduction To JavaScript
PDF
Java script tutorial
ODP
PDF
Tech friday 22.01.2016
PDF
An Introduction to ReactJS
PPTX
JavaScript Core fundamentals - Learn JavaScript Here
PDF
Async JavaScript Unit Testing
PDF
Debugging Javascript
PPTX
Introduction to react_js
ZIP
Automated Frontend Testing
PDF
Adventures in Laravel and Performance: Looking beyond eloquent
Présentation de HomeKit
ReactJS
Step objects
Good karma: UX Patterns and Unit Testing in Angular with Karma
Javascript
React.js enlightenment
Console in javaScript
Ajax
Introduction To JavaScript
Java script tutorial
Tech friday 22.01.2016
An Introduction to ReactJS
JavaScript Core fundamentals - Learn JavaScript Here
Async JavaScript Unit Testing
Debugging Javascript
Introduction to react_js
Automated Frontend Testing
Adventures in Laravel and Performance: Looking beyond eloquent
Ad

Viewers also liked (20)

PPSX
365 产品介绍 产品推广app_20150721
PPT
quick sort by student of NUML university
PDF
Php And Web Services
PDF
CV_Zhang Haochenzi 2015:10:08
PPT
Kewirausahaan
RTF
Bai tap trac_nghiem_16_units
PDF
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14
PPT
What Do You Want To Order
PDF
Jdj Foss Java Tools
PPTX
JS basics
PDF
Asat book0-fresh blood
PPTX
PLAZA 3.0 - an access point for plant comparative genomics
DOC
ルイ·ヴィトンの荷物を購入
PDF
Critical purviews where information and communication technology (ICT) can pr...
PDF
Q3 2013 ASSA ABLOY investors presentation 28 october
PDF
Authorized and Exclusive Distributor for Ecuador
PDF
Ipf vanhove scientix
PDF
PPTX
Mini-Training: Let's have a rest
365 产品介绍 产品推广app_20150721
quick sort by student of NUML university
Php And Web Services
CV_Zhang Haochenzi 2015:10:08
Kewirausahaan
Bai tap trac_nghiem_16_units
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14
What Do You Want To Order
Jdj Foss Java Tools
JS basics
Asat book0-fresh blood
PLAZA 3.0 - an access point for plant comparative genomics
ルイ·ヴィトンの荷物を購入
Critical purviews where information and communication technology (ICT) can pr...
Q3 2013 ASSA ABLOY investors presentation 28 october
Authorized and Exclusive Distributor for Ecuador
Ipf vanhove scientix
Mini-Training: Let's have a rest
Ad

Similar to Extending Ajax Events for all mankind (20)

PDF
Building Applications Using Ajax
PDF
How to Use AJAX in PHP and jQuery.pdf
PPT
Introduction to ajax
PPTX
JavaScript Multithread or Single Thread.pptx
PDF
Asynchronous development in JavaScript
PPT
PPT
PPT
Ajax Presentation
PDF
Beyond HTML: Tools for Building Web 2.0 Apps
ODP
JavaScript Web Development
PPTX
Introduction to Vert.x
PPT
Pascarello_Investigating JavaScript and Ajax Security
PDF
PPTX
Ajax assignment help
PPT
Ajax Lecture Notes
PDF
How to make Ajax Libraries work for you
PDF
How to make Ajax work for you
DOCX
PPT
symfony & jQuery (phpDay)
PPT
Ajax: User Experience
Building Applications Using Ajax
How to Use AJAX in PHP and jQuery.pdf
Introduction to ajax
JavaScript Multithread or Single Thread.pptx
Asynchronous development in JavaScript
Ajax Presentation
Beyond HTML: Tools for Building Web 2.0 Apps
JavaScript Web Development
Introduction to Vert.x
Pascarello_Investigating JavaScript and Ajax Security
Ajax assignment help
Ajax Lecture Notes
How to make Ajax Libraries work for you
How to make Ajax work for you
symfony & jQuery (phpDay)
Ajax: User Experience

More from Kyle Simpson (13)

PDF
HTML5 JavaScript On Crack
PDF
The Once And Future Script Loader (v3)
PPT
The Once And Future Script Loader (v2)
PPT
The Once And Future Script Loader (v1)
PPT
Server-side JavaScript for the rest of us
PPTX
Rise of the Middle End
PPTX
Dude, That's Some Strange UI Architecture
PPTX
UI Architecture & Web Performance
PPTX
Dude, where's my UI architecture?
PPT
No more script tag soup!
PPTX
JavaScript Architecture: The Front and the Back of It
PPT
JavaScript UI Architecture: Be all that you can be
PPT
Loading JavaScript: Even a caveman can do it
HTML5 JavaScript On Crack
The Once And Future Script Loader (v3)
The Once And Future Script Loader (v2)
The Once And Future Script Loader (v1)
Server-side JavaScript for the rest of us
Rise of the Middle End
Dude, That's Some Strange UI Architecture
UI Architecture & Web Performance
Dude, where's my UI architecture?
No more script tag soup!
JavaScript Architecture: The Front and the Back of It
JavaScript UI Architecture: Be all that you can be
Loading JavaScript: Even a caveman can do it

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
sap open course for s4hana steps from ECC to s4
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MYSQL Presentation for SQL database connectivity
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

Extending Ajax Events for all mankind

  • 2. who am i? kyle simpson @getify [email_address] http://getify.com
  • 3. what is the meaning of life? i dunno. maybe jQuery? or 42. something like that.
  • 4. so, why are we here? I’m glad you asked.
  • 5. extending ajax events for all mankind… jQuery Conf 2009
  • 6. our little chat today what are Ajax events? how does jQuery handle Ajax events? why would I want to extend them? gimme some real code! mpAjax flXHRproxy
  • 7.  
  • 8. what are Ajax events? events specifically triggered when Ajax requests happen. duh. $([‘Complete’,’Error’,’Send’,’Start’,’Stop’,’Success’]).each(function() { console.log(‘ajax’ + this); }); technically, an event is a signal to jQuery to call one or more registered callback functions to let them know something happened. blah, blah, blah.
  • 9. how does jQuery handle Ajax events? “ a tale of two cities” per-request (aka, “local”) callback functions as parameters/options to $.ajax(), $.get(), $.post(), etc global events listeners bound to DOM element(s) triggered with every Ajax call
  • 10. how does jQuery handle Ajax events? per-request callbacks: ‘ beforeSend’, ‘complete’, ‘error’, ‘success’, ‘timeout’ different function signatures (parameters) only one registered callback per event per request
  • 11. how does jQuery handle Ajax events? global events: “ ajax___” where ___ is one of: ‘Complete’,’Error’,’Send’,’Start’,’Stop’,’Success’ can be bound to whatever DOM element(s) you choose; all handlers get called for each event ‘ Start’ and ‘Stop’ are special consistent function signature can be disabled per-request via ‘global:false’
  • 12. … try to take over the Ajax event.
  • 13. how does jQuery handle Ajax events? so, how can we use them? hide/show loading “spinner” show generic error message resubmit a request on timeout
  • 14. how does jQuery handle Ajax events? hide/show loading “spinner”:
  • 15. how does jQuery handle Ajax events? show generic error message:
  • 16. how does jQuery handle Ajax events? resubmit a request on timeout:
  • 17. why would I want to extend them? overall goal == better code organization existing events not granular enough monolithic callback functions with ‘switch’ extend (or override) existing functionality change callback signature additional pre- or post-processing on requests or responses
  • 18. why would I want to extend them? some extension ideas: request retry on timeout “ application error” event handling smarter response caching ordered responses via request/response queue solve “travelling salesman” problem
  • 19. gimme some real code! example: application-level success/error
  • 20. gimme some real code! example: application-level success/error
  • 21. mpAjax multi-part Ajax *responses* -- return multiple different "parts" of data (different types, etc) in a single response. return a block of HTML (without encoding/escaping it into JSON), and a separate JSON packet with data return an HTML template and some JSON data separately, without any obfuscation/encoding/escaping of either return some HTML, some JSON, and also some CSS, and handle all three types of data separately return two or more different blocks of HTML, and need to handle each separately
  • 22. mpAjax strategy: post-process data from a ‘success’ful Ajax request if multi-part format found, string parse response text, send each part to separate response handler otherwise, behave exactly like normal Ajax request/response
  • 23. mpAjax mpAjax jQuery plugin: http://plugins.jquery.com/project/mpAjax code: http://plugins.jquery.com/files/jquery.mpAjax.js_6.txt demo: http://test.getify.com/mpAjax
  • 24. flXHRproxy flXHR is a javascript API wrapper that mimics native XHR object in almost every way, but behind the scenes, makes calls via an invisible flash asset (crossdomain.xml) flXHRproxy adapts jQuery to use flXHR for fully featured cross-domain Ajax uses the jQuery plugin ‘XHR’ to register flXHR as a XHR clone registers/associates specific flXHR config options with a specific target URL
  • 25. flXHRproxy strategy: register flXHR as XHR drop-in replacement extend ‘success’ function signature (parameters) to include the XHR object tie flXHR’s ‘onerror’ event to trigger the jQuery ‘error’ events
  • 26. flXHRproxy flXHR: http://flxhr.flensed.com flXHRproxy jQuery plugin: http://plugins.jquery.com/search/node/fxhr code: http://plugins.jquery.com/files/jquery.flXHRproxy.js_3.txt demo: http://flxhr.flensed.com/code/tests/flxhr-7e.html
  • 27. enjoy http://plugins.jquery.com/project/mpAjax http://test.getify.com/mpAjax http://plugins.jquery.com/project/flXHR http://flxhr.flensed.com/jquery.php rate this talk: http://speakerrate.com/talks/1408-extending-ajax-events-for-all-mankind