- 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.
- Painter 現代服裝效果圖表現技法
- JasperReports for Java Developers
- Sencha Touch Cookbook, Second Edition
- OpenStack實戰指南
- 邊做邊學:Photoshop CS6 圖像制作案例教程
- 移動App測試的22條軍規
- Rhino 6.0中文版入門、精通與實戰
- 中文版Premiere Pro CC實用教程
- 攝影照片修飾完全自學手冊
- 計算機·手機生活應用
- Creo 4.0從入門到精通
- NetLogo多主體建模入門
- CINEMA 4D R20完全實戰技術手冊
- Adobe創意大學InDesign CS5 產品專家認證標準教材
- 中文版Photoshop平面設計入門教程