Doing AJAX in WordPress

Slides:



Advertisements
Similar presentations
LiNC Developer Meetup Welcome!. Our job is to make your life easier APIs Tools and workflow Documentation Stay in touch: developers.lithium.com Join the.
Advertisements

Extreme User Interfaces for Alfresco Kevin Dorr Sr. Solutions Engineer Americas Channel.
AJAX Asynchronous Javascript And XML. AJAX A lot of hype –It has been around for a while –Not complex Powerful approach to building websites –Think differently.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 11– Ajax Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman.
Javascript and AJAX Willem Visser RW334. Overview Javascript jQuery AngularJS AJAX.
IS 360 Course Introduction. Slide 2 What you will Learn (1) The role of Web servers and clients How to create HTML, XHTML, and HTML 5 pages suitable for.
Multiple Tiers in Action
1 The World Wide Web Architectural Overview Static Web Documents Dynamic Web Documents HTTP – The HyperText Transfer Protocol Performance Enhancements.
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
Agenda What is AJAX? What is jQuery? Demonstration/Tutorial Resources Q&A.
Making AJAX Easy with jQuery Chris Renner Health Systems Analyst Programmer & Informatics Manager VUMC Office of Grants & Contracts Management October.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Internet Applications Spring Review Last week –MySQL –Questions?
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
JavaScript & jQuery the missing manual Chapter 11
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Ajax - Part II Communicating with the Server. Learning Objectives By the end of this lecture, you should be able to: – Describe the overview of steps.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
JavaScript is a client-side scripting language. Programs run in the web browser on the client's computer. (PHP, in contrast, is a server-side scripting.
SHOPPING CARTS CHAPTER 19. E-COMMERCE Typically, an e-commerce site will have public pages and admin pages.
Cross Site Integration “mashups” cross site scripting.
WordPress Plugin Development A Starter Guide For Beginners.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
SYST Web Technologies SYST Web Technologies AJAX.
Ajax for Dynamic Web Development Gregory McChesney.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
Display Page (HTML/CSS)
Programmer Support. Our Primary Goal: Reproduce the Problem.
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
Javascript AJAX HTML WEB SERVER Asynchronous. Javascript HTML events DOM – document object model browser internal view of html page compute.
Wes Preston DEV 202. Audience: Info Workers, Dev A deeper dive into use-cases where client-side rendering (CSR) and SharePoint’s JS Link property can.
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
How to consume a RESTful service using jQuery. Introduction  In this post we see how to consume the RESTful service described in the post Design a RESTful.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
Extreme User Interfaces for Alfresco Kevin Dorr Sr. Solutions Engineer Americas Channel.
National College of Science & Information Technology.
Introduction To Simple WordPress Plugin Development
Web API - Introduction AJAX, Spring Data REST SoftUni Team Web API
JavaScript and Ajax (Ajax Tutorial)
Developing WordPress Plugins
PHP –MySQL Interview Question And Answer.
What is REST API ? A REST (Representational State Transfer) Server simply provides access to resources and the REST client accesses and presents the.
Introduction to jQuery
Function Test Framework
CSE 154 Lecture 24: JSON.
JavaScript Client-side
INFO 344 Web Tools And Development
WordPress Plugins.
Tutorial (4): HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
IS 360 Course Introduction
Web Browser server client 3-Tier Architecture Apache web server PHP
jQuery form submission
HTTP Request Method URL Protocol Version GET /index.html HTTP/1.1
JavaScript & jQuery AJAX.
Web Programming Language
MIS Professor Sandvig MIS 324 Professor Sandvig
Chengyu Sun California State University, Los Angeles
A Beginners Session to Ajax
ხელმძღვანელი: დიმიტრი ქარაული
MVC – Model View Controller
DR. JOHN ABRAHAM PROFESSOR UTPA
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
C++ Final Presentation.
MIS Professor Sandvig MIS 424 Professor Sandvig
PHP and JSON Topics Review JSON.
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

Doing AJAX in WordPress Micah Wood / @wpscholar

Enqueuing Scripts wp_enqueue_script( $handle = 'ajax-yall', $source = plugins_url( 'ajax.js', __FILE__ ), $dependencies = array( 'jquery' ), );

Use the Right Hook! Right: wp_enqueue_scripts Wrong: wp_print_scripts wp_head

Passing Data to JavaScript wp_localize_script( $handle = 'ajax-yall', $object_name = 'ajaxYall', $data = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'ajaxin-it' ), ) );

jQuery Makes Life Easy jQuery(document).ready(function($) { // DO COOL STUFF });

Use the Best Request Type // Fetch data $.get(); // Modify data $.post();

A Typical AJAX Request $('#my-element').click( function() { $.get( ajaxYall.ajaxurl, { action: 'ajaxin-it', nonce: ajaxYall.nonce, postID: ID }, function( data, textStatus, jqXHR ) { if( jqXHR.status == 200 && textStatus == 'success' ) { // Do stuff } }, 'json' // Can also be xml, script, or html ); } );

WordPress AJAX Handling $my_action = 'ajaxin-it'; if( defined( 'DOING_AJAX' ) && DOING_AJAX ) { // For logged in users add_action( 'wp_ajax_' . $my_action, 'do_stuff' ); // For logged out users add_action( 'wp_ajax_nopriv_' . $my_action, 'do_stuff' ); }

Respond to the Request <?php function do_stuff() { if( wp_verify_nonce( $_GET['nonce'], 'ajaxin-it' ) ){ 
        $response = array( 'status' => 'success', 'message' => "It's AJAX Y'all!", ); header( 'Content: application/json' ); echo json_encode( $response ); die; }

Questions

Get in Touch Micah Wood @wpscholar http://micahwood.me