內容簡介
AHAX 是一個即插即用的解決方案,允許主題或外掛程式開發人員利用簡單而精簡的方式來進行 AJAX 請求。
此外掛程式的目標是讓建立 AJAX 請求的流程盡可能簡單。
此外掛程式圍繞著「動作(action)」來進行 AJAX 請求。該動作「綁定(bind)」到後端的一個函式(處理程序),並透過自訂的 JavaScript 類別方法從前端呼叫該函式。
後端
ahax::bind( 'get_random_number', 'generate_number' ); function generate_number($output) { $max = abs( ( int ) $_POST['max'] ); $output = mt_rand( 0 , ( $max <= 1000 ? $max : 1000 ) ); return $output; }
前端
var ahax = new AHAX(); ahax.post( 'get_random_number', { max : 1000 }, function( response ) { jQuery( '#ahax_number' ).html( response ); });
網站
http://dan.doezema.com/2011/04/ahax-wordpress-plugin
作者
Daniel Doezema
外掛標籤
開發者團隊
原文外掛簡介
AHAX is a drop-in solution that allows theme or plug-in developers to take advantage of a very simple and streamlined way of making AJAX requests.
The goal of this plugin is to make the process of setting up an AJAX request as simple as possible.
This plugin centers AJAX requests around an “action.” This action is “bound” to a function (handler) on the back-end and called to from front-end via a custom JavaScript class method — this process is demonstrated below.
Back-End
ahax::bind( 'get_random_number', 'generate_number' ); function generate_number($output) { $max = abs( ( int ) $_POST['max'] ); $output = mt_rand( 0 , ( $max <= 1000 ? $max : 1000 ) ); return $output; }
Front-End
var ahax = new AHAX(); ahax.post( 'get_random_number', { max : 1000 }, function( response ) { jQuery( '#ahax_number' ).html( response ); });
Website
http://dan.doezema.com/2011/04/ahax-wordpress-plugin
Author
Daniel Doezema
