$("#test").click(function() { $.ajax({ type: "GET", url: "default.aspx", beforeSend: function(request) { request.setRequestHeader("Test", "Chenxizhang"); }, success: function(result) { alert(result); } }); });
现在jquery已经成了Javascript实际标准了,要在ajax请求之前添加头信息。在jquery的ajax函数中有个beforeSend方法,这个方法接受一个参数就是XMLHttpRequest对象。调用该对象的setRequestHeader方法实现。