Add Custom Header__jquery in Jquery

Source: Internet
Author: User
Tags jquery library

We know that you can add a custom request header when you send an AJAX request

Beforesend:function (Request) {
        Request.setrequestheader ("Test", "Chenxizhang");
}

However, you need to add a header to each AJAX request. So you can change the jquery library to do this.

We found the following code:

Setrequestheader:function (name, value) {
                    var lname = Name.tolowercase ();
                    if (!state) {
                        name = requestheadersnames[LName] = requestheadersnames[LName] | | name;
                        requestheaders[name] = value;
                        requestheaders["yourname"] = "Yourvalue";
                    }
                    return this;
                }

We can see that the send request header is sent in this place, so you can manually add the parameter of the request header and the value to meet the requirement in this position. Or you can override the Ajax method to extend the use.

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.