Add custom header information to jquery Ajax

Source: Internet
Author: User

go from Network
1
$.ajax ({2Type: "POST",3URL: "Http://192.168.0.88/action.cgi?ActionID=WEB_RequestCertificateAPI",4 data: {5"User": "API",6"Password": "API"7 },8DataType: "JSON",9ContentType: "Application/json",TenBeforesend:function(XMLHttpRequest) { One //Httputility.urlencode A varSessionID = "SessionID"; - Xmlhttprequest.setrequestheader (SessionID, sid); - }, theSuccessfunction(SessionID) { - //alert (sessionid.success); - varDT = eval ("(" + Sessionid.data + ")"); - if(Sessionid.success = = 1) { +Alert ("Success"); - } + Else { AAlert (' ErrorID: ' +SessionID.error.id); atAlert (' ErrorCode: ' +SessionID.error.code); -Alert (' Errorpara: ' +SessionID.error.params); - } - } -});
For various reasons, in their own framework to pass the system agreed to the header information, the page uses the jquery Ajax request, looked for a long time, suddenly found that we can be set in the Beforesend method, this method accepts a parameter, Represents the XMLHttpRequest object that initiates an asynchronous request, and we can use the object's setRequestHeader method to achieve our purpose, for example, I add a custom datatype header message to the header:
Beforesend:function (XMLHttpRequest) {
Xmlhttprequest.setrequestheader ("DataType", "abc");
$ (". Return_confrim"). HTML ("     Verifying account ... ");
},
In this way, we can get the datatype information in the customization on the server side.

Add custom header information to jquery Ajax

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.