Now Ajax is widely used and there are many good Ajax frameworks available. Ajax is an asynchronous request and mainly a client script behavior. So, how do I add some special header information for the request before the request?
The following is a simple example. I wrote it using jquery. In its Ajax function, there is a beforesend method. This method accepts a parameter and represents the XMLHTTPRequest object that initiates an asynchronous request, we can use the setRequestHeader method of this object to achieve our goal.
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default2.aspx. cs" inherits = "default2" %> <! Doctype Html Public "-// W3C // dtd xhtml 1.0 transitional // en" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < Html Xmlns = "Http://www.w3.org/1999/xhtml" > < Head Runat = "Server" > < Title > </ Title > < Script SRC = "Jquery-1.3.2-vsdoc.js" Type = "Text/JavaScript" > </ Script > <SCRIPT type ="Text/JavaScript" Language = "JavaScript" > $ ( Function () {$ ( "# Test" ). Click ( Function () {$. Ajax ({type: "Get" , URL: "Default. aspx" , Beforesend: Function (Request) {request. setRequestHeader ( "Test" , "Chenxizhang" ) ;}, Success: Function (Result) {alert (result );}});});}); </ Script > </ Head > < Body > < Form ID = "Form1" Runat = "Server" > < Div ID = "V" > </ Div > < Input Type = "Button" Value = "Test" ID = "Test" /> </ Form > </ Body > </ Html >