SlideShare a Scribd company logo
AJAX the WordPress way
●
    Justin Foell
●
    WordPress Developer @ 9seeds.com
●
    justin@9seeds.com
●
    @justinfoell
What is AJAX?
●
    Asynchronous JavaScript and XML
●
    A fast way of getting data or a portion of a
    page from the web server w/o having to do a
    full page request
How does AJAX work
            (in WordPress)?
●
    jQuery makes an AJAX call to the server from
    your browser
●
    WordPress routes the call appropriately
●
    The call is processed by WordPress core - or
    a theme or plugin - which returns HTML or
    JSON (JavaScript Object Notation) data
●
    Returned data is displayed appropriately
Required Pieces
●
    JavaScript (and form) on to trigger an AJAX
    call
●
    WordPress hook (wp_ajax_* action) to route
    the request
●
    A function to handle the request and return
    the expected result
Dirty Details
    Getting JavaScript/jQuery loaded
●
    Register & Enqueue your JavaScript using
    wp_register_script & wp_enqueue_script
●
    Remember to include 'jquery' as a dependency when
    registering your script, so it automagically gets loaded
●
    Use wp_localize_script to expose WordPress variables
    to JavaScript – such as the ajax submit URL (only
    needed for Front-End AJAX)
●
    AJAX calls always go to admin_url( 'admin-ajax.php' )
    regardless if they're made from the front-end or wp-
    admin
Dirty Details (cont.)
    JavaScript/jQuery AJAX call
●
    Use jQuery AJAX Shorthand Methods
●
    The data object should have a member
    variable called 'action' – the value of it will
    correspond to the WordPress action
    executed...
Dirty Details (cont.)
    WordPress ajax hook
    add_action( 'wp_ajax_<action-value>', 'function_to_run_on_ajax_call' );

●
    Should return valid HTML or JSON data
●
    You MUST exit or die!!!111one
WordPress Admin Example
●
    Almost the same as the front-end example
●
    Hook form into an existing page or add your
    form to a custom wp-admin page
●
    Register & Enqueue javascript
●
    ajaxurl is already set
●
    Use json_encode in WordPress
●
    Use jQuery.parseJSON in jQuery
Questions???
Thank you!
●
    Justin Foell – Developer @ 9seeds.com
●
    justin@9seeds.com
    Resources:
●
    api.jquery.com/category/ajax/shorthand-methods
●
    codex.wordpress.org/AJAX_in_Plugins
●
    Code: bit.ly/jf-wordup-2012
●
    Slides: bit.ly/jf-slides-wordup-2012

More Related Content

PDF
Ajax and RJS
PPT
jQuery and AJAX with Rails
PPTX
ASP.NET MVC and ajax
PDF
Introduction to react
PDF
Introduction to AJAX In WordPress
PDF
Understanding Facebook's React.js
PDF
React Introduction
PDF
Web without framework
Ajax and RJS
jQuery and AJAX with Rails
ASP.NET MVC and ajax
Introduction to react
Introduction to AJAX In WordPress
Understanding Facebook's React.js
React Introduction
Web without framework

What's hot (20)

PDF
Introduction to angular js july 6th 2014
KEY
Architecting single-page front-end apps
PPSX
React introduction
PPTX
Webinar: AngularJS and the WordPress REST API
PDF
Server rendering-talk
PDF
JavaScript straight from the Oracle Database
PPTX
AngularJS for Java Developers
PPTX
Introduction To JavaScript Ajax
PPTX
Academy PRO: React JS. Redux & Tooling
PDF
Web Worker, Service Worker and Worklets
PDF
ClojureScript: I can't believe this is JavaScript
PPTX
Being a pimp without silverlight
PPTX
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
PDF
More efficient, usable web
PDF
Web a Quebec - JS Debugging
PDF
MVC 1.0 als alternative Webtechnologie
PPTX
Making Single Page Applications (SPA) faster
PPTX
Ajax assignment help
PPTX
Introduction to ASP.NET MVC
PPTX
Ajax and ASP.NET AJAX
Introduction to angular js july 6th 2014
Architecting single-page front-end apps
React introduction
Webinar: AngularJS and the WordPress REST API
Server rendering-talk
JavaScript straight from the Oracle Database
AngularJS for Java Developers
Introduction To JavaScript Ajax
Academy PRO: React JS. Redux & Tooling
Web Worker, Service Worker and Worklets
ClojureScript: I can't believe this is JavaScript
Being a pimp without silverlight
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
More efficient, usable web
Web a Quebec - JS Debugging
MVC 1.0 als alternative Webtechnologie
Making Single Page Applications (SPA) faster
Ajax assignment help
Introduction to ASP.NET MVC
Ajax and ASP.NET AJAX
Ad

Viewers also liked (19)

PPT
Module 8 Preparation
ODP
Building your first WordPress plugin
PDF
เล่มจริง
ODP
Where do I go from here?
PPT
Biofuels
PPT
Module 7 Preparation
PPS
Naica crystalcavemexico
PPT
Module 7 Interaction
ODP
Pimp your Gmail to get more done
PPT
Module 6 Interaction
PPT
Module 8 Interaction
PPTX
Nginx [engine x] and you (and WordPress)
PDF
S peters final_dse
PPT
New york city
ODP
Customizing the WP Admin for fun and profit
PPT
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
ODP
Minimum Viable Product
PPT
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
PPTX
27 simple sentences
Module 8 Preparation
Building your first WordPress plugin
เล่มจริง
Where do I go from here?
Biofuels
Module 7 Preparation
Naica crystalcavemexico
Module 7 Interaction
Pimp your Gmail to get more done
Module 6 Interaction
Module 8 Interaction
Nginx [engine x] and you (and WordPress)
S peters final_dse
New york city
Customizing the WP Admin for fun and profit
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
Minimum Viable Product
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
27 simple sentences
Ad

Similar to AJAX the WordPress way (20)

PDF
WCLA12 JavaScript
PPT
PPT
Ajax tutorial by bally chohan
PPT
PPT
Ajax Tuturial
PDF
Introduction to AngularJS For WordPress Developers
PDF
PDF
1 ppt-ajax with-j_query
PDF
JavaScript & AJAX in WordPress
ODP
PDF
Jqeury ajax plugins
PDF
Jqeury ajax plugins
PPT
mukesh
PDF
Unobtrusive JavaScript
PPT
WordPress and Ajax
PPT
PDF
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
PDF
How to make Ajax work for you
PDF
Apache Wicket Web Framework
WCLA12 JavaScript
Ajax tutorial by bally chohan
Ajax Tuturial
Introduction to AngularJS For WordPress Developers
1 ppt-ajax with-j_query
JavaScript & AJAX in WordPress
Jqeury ajax plugins
Jqeury ajax plugins
mukesh
Unobtrusive JavaScript
WordPress and Ajax
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
How to make Ajax work for you
Apache Wicket Web Framework

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Digital-Transformation-Roadmap-for-Companies.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

AJAX the WordPress way

  • 1. AJAX the WordPress way ● Justin Foell ● WordPress Developer @ 9seeds.com ● justin@9seeds.com ● @justinfoell
  • 2. What is AJAX? ● Asynchronous JavaScript and XML ● A fast way of getting data or a portion of a page from the web server w/o having to do a full page request
  • 3. How does AJAX work (in WordPress)? ● jQuery makes an AJAX call to the server from your browser ● WordPress routes the call appropriately ● The call is processed by WordPress core - or a theme or plugin - which returns HTML or JSON (JavaScript Object Notation) data ● Returned data is displayed appropriately
  • 4. Required Pieces ● JavaScript (and form) on to trigger an AJAX call ● WordPress hook (wp_ajax_* action) to route the request ● A function to handle the request and return the expected result
  • 5. Dirty Details Getting JavaScript/jQuery loaded ● Register & Enqueue your JavaScript using wp_register_script & wp_enqueue_script ● Remember to include 'jquery' as a dependency when registering your script, so it automagically gets loaded ● Use wp_localize_script to expose WordPress variables to JavaScript – such as the ajax submit URL (only needed for Front-End AJAX) ● AJAX calls always go to admin_url( 'admin-ajax.php' ) regardless if they're made from the front-end or wp- admin
  • 6. Dirty Details (cont.) JavaScript/jQuery AJAX call ● Use jQuery AJAX Shorthand Methods ● The data object should have a member variable called 'action' – the value of it will correspond to the WordPress action executed...
  • 7. Dirty Details (cont.) WordPress ajax hook add_action( 'wp_ajax_<action-value>', 'function_to_run_on_ajax_call' ); ● Should return valid HTML or JSON data ● You MUST exit or die!!!111one
  • 8. WordPress Admin Example ● Almost the same as the front-end example ● Hook form into an existing page or add your form to a custom wp-admin page ● Register & Enqueue javascript ● ajaxurl is already set ● Use json_encode in WordPress ● Use jQuery.parseJSON in jQuery
  • 10. Thank you! ● Justin Foell – Developer @ 9seeds.com ● justin@9seeds.com Resources: ● api.jquery.com/category/ajax/shorthand-methods ● codex.wordpress.org/AJAX_in_Plugins ● Code: bit.ly/jf-wordup-2012 ● Slides: bit.ly/jf-slides-wordup-2012