官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 娄烦县| 乌兰浩特市| 二连浩特市| 贵港市| 化隆| 永和县| 大新县| 岗巴县| 岳阳市| 高邮市| 诸城市| 兴化市| 泾阳县| 耒阳市| 桐乡市| 新巴尔虎左旗| 成武县| 台安县| 蒙阴县| 迁西县| 红河县| 炎陵县| 巴彦淖尔市| 屏东县| 威信县| 四会市| 秦皇岛市| 民丰县| 盐边县| 宣城市| 邢台县| 永登县| 固镇县| 六安市| 贞丰县| 九台市| 湖南省| 成安县| 伊川县| 盐边县| 隆子县|