SlideShare a Scribd company logo
1 of 10
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

What's hot

Db migration automation
Db migration automationDb migration automation
Db migration automationThomas Queste
 
Introduction to angular js july 6th 2014
Introduction to angular js   july 6th 2014Introduction to angular js   july 6th 2014
Introduction to angular js july 6th 2014Simona Clapan
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end appsZohar Arad
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWP Engine UK
 
Server rendering-talk
Server rendering-talkServer rendering-talk
Server rendering-talkDaiwei Lu
 
JavaScript straight from the Oracle Database
JavaScript straight from the Oracle DatabaseJavaScript straight from the Oracle Database
JavaScript straight from the Oracle DatabaseDimitri Gielis
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java DevelopersLoc Nguyen
 
Introduction To JavaScript Ajax
Introduction To JavaScript AjaxIntroduction To JavaScript Ajax
Introduction To JavaScript AjaxReema
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
Web Worker, Service Worker and Worklets
Web Worker, Service Worker and WorkletsWeb Worker, Service Worker and Worklets
Web Worker, Service Worker and WorkletsKeshav Gupta
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptEric Normand
 
Being a pimp without silverlight
Being a pimp without silverlightBeing a pimp without silverlight
Being a pimp without silverlightMaarten Balliauw
 
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High GearASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High GearKevin Griffin
 
More efficient, usable web
More efficient, usable webMore efficient, usable web
More efficient, usable webChris Mills
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS DebuggingRami Sayar
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieOPEN KNOWLEDGE GmbH
 
Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster Boris Livshutz
 
Ajax assignment help
Ajax assignment helpAjax assignment help
Ajax assignment helpjohn mayer
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Joe Wilson
 

What's hot (20)

Db migration automation
Db migration automationDb migration automation
Db migration automation
 
Introduction to angular js july 6th 2014
Introduction to angular js   july 6th 2014Introduction to angular js   july 6th 2014
Introduction to angular js july 6th 2014
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
 
React introduction
React introductionReact introduction
React introduction
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Server rendering-talk
Server rendering-talkServer rendering-talk
Server rendering-talk
 
JavaScript straight from the Oracle Database
JavaScript straight from the Oracle DatabaseJavaScript straight from the Oracle Database
JavaScript straight from the Oracle Database
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
Introduction To JavaScript Ajax
Introduction To JavaScript AjaxIntroduction To JavaScript Ajax
Introduction To JavaScript Ajax
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
Web Worker, Service Worker and Worklets
Web Worker, Service Worker and WorkletsWeb Worker, Service Worker and Worklets
Web Worker, Service Worker and Worklets
 
ClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScriptClojureScript: I can't believe this is JavaScript
ClojureScript: I can't believe this is JavaScript
 
Being a pimp without silverlight
Being a pimp without silverlightBeing a pimp without silverlight
Being a pimp without silverlight
 
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High GearASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
ASP.NET Quick Wins - 20 Tips and Tricks To Shift Your Application into High Gear
 
More efficient, usable web
More efficient, usable webMore efficient, usable web
More efficient, usable web
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS Debugging
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
 
Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster
 
Ajax assignment help
Ajax assignment helpAjax assignment help
Ajax assignment help
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
 

Viewers also liked

Module 8 Preparation
Module 8 PreparationModule 8 Preparation
Module 8 Preparationschernick
 
Building your first WordPress plugin
Building your first WordPress pluginBuilding your first WordPress plugin
Building your first WordPress pluginJustin Foell
 
เล่มจริง
เล่มจริงเล่มจริง
เล่มจริงKrukook Sut
 
Where do I go from here?
Where do I go from here?Where do I go from here?
Where do I go from here?Justin Foell
 
Module 7 Preparation
Module 7 PreparationModule 7 Preparation
Module 7 Preparationschernick
 
Naica crystalcavemexico
Naica crystalcavemexicoNaica crystalcavemexico
Naica crystalcavemexicograndkidzrock
 
Module 7 Interaction
Module 7 InteractionModule 7 Interaction
Module 7 Interactionschernick
 
Pimp your Gmail to get more done
Pimp your Gmail to get more donePimp your Gmail to get more done
Pimp your Gmail to get more doneJustin Foell
 
Module 6 Interaction
Module 6 InteractionModule 6 Interaction
Module 6 Interactionschernick
 
Module 8 Interaction
Module 8 InteractionModule 8 Interaction
Module 8 Interactionschernick
 
Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)Nginx [engine x] and you (and WordPress)
Nginx [engine x] and you (and WordPress)Justin Foell
 
Customizing the WP Admin for fun and profit
Customizing the WP Admin for fun and profitCustomizing the WP Admin for fun and profit
Customizing the WP Admin for fun and profitJustin Foell
 
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمينعرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمينMOKBAL
 
Minimum Viable Product
Minimum Viable ProductMinimum Viable Product
Minimum Viable ProductJustin Foell
 
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمينعرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمين
عرض بور بوينت عن اخلاقيات استخدام الانترنت وحماية المستخدمينMOKBAL
 
27 simple sentences
27 simple sentences27 simple sentences
27 simple sentencesvaibhav1996
 

Viewers also liked (19)

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

Similar to AJAX the WordPress way

Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohanWebVineet
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersCaldera Labs
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_queryFajar Baskoro
 
JavaScript & AJAX in WordPress
JavaScript & AJAX in WordPressJavaScript & AJAX in WordPress
JavaScript & AJAX in WordPressIgor Benić
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax pluginsInbal Geffen
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax pluginsInbal Geffen
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScriptVitaly Baum
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Nicolás Bouhid
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for youSimon Willison
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web FrameworkLuther Baker
 

Similar to AJAX the WordPress way (20)

WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Ajax
AjaxAjax
Ajax
 
Ajax Tuturial
Ajax TuturialAjax Tuturial
Ajax Tuturial
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
Ajax
AjaxAjax
Ajax
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
 
JavaScript & AJAX in WordPress
JavaScript & AJAX in WordPressJavaScript & AJAX in WordPress
JavaScript & AJAX in WordPress
 
Ajax3
Ajax3Ajax3
Ajax3
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
mukesh
mukeshmukesh
mukesh
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
Ajax on drupal the right way - DrupalCamp Campinas, São Paulo, Brazil 2016
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
 

Recently uploaded

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

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