- WordPress Plugin Development Beginner's Guide
- Vladimir Prelovac
- 200字
- 2021-05-21 20:12:21
Time for action – Use advanced Ajax call
In this example, we will replace the simple Ajax call with a more advanced one that offers us more options and controls.
Open the wp-live-blogroll.js.php
file and replace the load()
function with the ajax()
function:
$.ajax({ type: "GET", url: LiverollSettings.plugin_url + '/wp-live-blogroll-ajax.php', timeout: 3000, data: { link_url: this.href }, success: function(msg) { jQuery('#lb_popup').html(msg); jQuery('#lb_popup').fadeIn(300); }, error: function(msg) { jQuery('#lb_popup').html('Error: ' + msg.responseText); } })
What just happened?
We have used an advanced jQuery function for handling the Ajax request, which obviously offers us more parameters.
The function allows us to specify the request type ('POST
' or 'GET
'), maximum script timeout and handlers for success and error results. This gives us full control over the events.
Tip
Full reference of the Ajax()
function and available parameters are available at http://docs.jquery.com/Ajax/jQuery.Ajax
Ajax script security using nonces
WordPress provides a simple to use, but powerful security mechanism to protect your scripts from unauthorised execution by using the so called nonces.
Nonce means number used once and represents a unique number much like a password generated each time the script runs. The idea is to use nonces in order to verify whether our request was authentic.
- Oracle SOA Suite Developer's Guide
- Photoshop CS6 商業應用案例實戰
- SketchUp印象 城市規劃項目實踐(第2版)
- 青少年美育趣味課堂:青少年學攝影修圖
- Puppet 2.7 Cookbook
- 詳解AutoCAD 2022機械設計(第6版)
- 3ds Max 2015中文版從入門到精通
- NHibernate 3.0 Cookbook
- SOLIDWORKS 2020產品設計基本功特訓(第3版)
- GlassFish Administration
- 中文版CorelDRAW X6基礎培訓教程(第2版)
- Building Websites with PHP/Nuke
- After Effects 2022從入門到精通
- Photoshop CC 2019 平面設計實例教程
- Choosing an Open Source CMS: Beginner's Guide