Ajax Small Extension

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.