Home>Article>Web Front-end> How to change header with jquery ajax
Jquery ajax method to change the header: 1. Set the header through the "$.ajax({undefined headers: {...}})" method; 2. Set the header using the beforeSend method.
The operating environment of this article: windows7 system, jquery3.2.1 version, DELL G3 computer
How to change the header of jquery ajax?
Two ways to set headers in jquery ajax
1. Setting parameter headers
$.ajax({undefined headers: { Accept: "application/json; charset=utf-8" }, type: "get", success: function (data) { } });
2. beforeSend method
$("#test").click(function() { $.ajax({ type: "GET", url: "default.aspx", beforeSend: function(request) { request.setRequestHeader("Test", "Chenxizhang"); }, success: function(result) { alert(result); } }); });
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to change header with jquery ajax. For more information, please follow other related articles on the PHP Chinese website!