- 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.
- Alfresco Developer Guide
- 中文版3ds Max 2012實用教程(第2版)
- 像攝影師一樣調色
- Android從入門到精通
- Microsoft Dynamics GP 2010 Reporting
- Apache Maven 3 Cookbook
- AutoCAD 2017從新手到高手
- Microsoft SQL Azure Enterprise Application Development
- Origin科技繪圖與數據分析
- Audition CC音頻處理完全自學一本通
- Instant MDX Queries for SQL Server 2012
- Flash Multiplayer Virtual Worlds
- Python Geospatial Development
- Excel達人手冊:表格設計的重點、難點與疑點精講
- phpBB: A User Guide