Ajax requests, you will encounter this situation, such as the need to take the same authentication parameters in each AJAX request, whether there is a method to automatically take these parameters in the AJAX request to automatically bring it?
We all know that the Ajaxsetup function of jquery can modify the default setting options for AJAX requests before Ajax initiates a request, and then perform an AJAX request that, if the corresponding option parameter is not set, will use the changed default settings. The options you set are stored in jquery.ajaxsettings.
$.ajaxsetup ({ data: { "XXXX" /// on each AJAX request with token parameter }});
At the time of the AJAX request, the parameters of the default settings in Ajaxsettings are merged,
However, Ajaxsetup does not take effect on a GET request and does not merge parameters that take effect on the POST request. The query string has already been placed on the URL because of the GET request. For GET requests, we can solve this problem by extending Ajax
(function ($) { var _ajax = $.ajax; $.extend ({ function (o) { //todo if( O.data) { //... } return _ajax.call (this, O); } );}) (jQuery);
Reference: Https://groups.google.com/forum/#!topic/jquery-dev/OBcEfgvTJ9I
Ajax Small Extension