1. Trang chủ
  2. » Công Nghệ Thông Tin

Using AJAX in your plugins and themes

19 158 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 19
Dung lượng 521,37 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

This article, aimed at plugin developers, describes how to add Ajax to a plugin. Before reading this article, you should be familiar with the following: Ajax - Overview of the technology Writing a Plugin - How to write a plugin Plugin API - Filters and actions - what they are and how to use them How to add HTML to the appropriate WordPress page, post, or screen -- for instance, if you want to add Ajax to administration screens you create, you will need to understand how to add administration menus to WordPress; if you want to add Ajax to the display of a single post, you'll need to figure out the right filters and actions to add HTML to that spot on viewer-facing blog screens.

Trang 1

G E T T H E S L I D E S

H T T P : / / W W W I T S A N A N D E R S O N C O M / W C S E A P D F

Using Ajax in Your Plugins and

Themes

Trang 2

About Me

Trang 3

Ajax – “What Does it Mean?”

Synchronous Requests Asynchronous Requests

“Asynchronous JavaScript and XML”

Trang 4

Simplify With jQuery

Trang 5

jQuery Basics – No Conflict

Trang 6

jQuery Basics – Ajax Response Types

evaluation

the page

Trang 7

Ajax in WordPress – Queue Your Script

 Use wp_enqueue_script() to add your script to a page

 handle – Name of script, e.g “my-awesome-script”

 src – Where your script can be found

 Use get_template_directory_uri() in parent themes

 Use get_stylesheet_directory_uri() in child themes

 Use plugins_url( „script.js‟, FILE ) in plugins

 deps – An array of scripts that this script relies on, by handle If you need jQuery, use something like “array( „jquery‟ )” Go to wp_enqueue_script Codex page for a list of

available dependencies

 ver – The version of the script Useful for “cachebusting” when your plugin is updated

 in_footer – Whether to place the script in the footer (rather than the header) Defaults to false

Trang 8

Ajax in WordPress – Queue Your Script (cont‟d)

Examples

Trang 9

Ajax in WordPress – Queue Your Script (cont‟d)

intelligently

conditional tags

Trang 10

Ajax in WordPress – Making Requests

 Admin Ajax

 Use „ajaxurl‟ variable

 Frontend Ajax

 Use „wp_localize_script‟ function

 Use „init‟ hook

Trang 11

Ajax in WordPress – Making Requests

Admin Ajax

Make sure you check user permissions Any logged in user can make ajax requests

Trang 12

Ajax in WordPress – Making Requests

Frontend Ajax – wp_localize_script

Trang 13

Ajax in WordPress – Making Requests

Frontend Ajax – init

Trang 14

Ajax in WordPress – Another Response Type

Another Response Type – json

Trang 15

Simplify Your Ajax Handlers

Trang 16

Simplify Your Ajax Handlers

Trang 17

Simplify Your Ajax Handlers

Trang 18

Example Plugin

Simple Post Ratings

Trang 19

Questions?

Will Anderson

http://www.itsananderson.com/

@itsananderson will@itsananderson.com

Ngày đăng: 12/05/2014, 23:40

TỪ KHÓA LIÊN QUAN

w