Home > Web Front-end > Front-end Q&A > How to change header with jquery ajax

How to change header with jquery ajax

藏色散人
Release: 2021-12-01 11:31:47
Original
6208 people have browsed it

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.

How to change header with jquery ajax

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) {
    }
});
Copy after login

2. beforeSend method

$("#test").click(function() {
                $.ajax({
                    type: "GET",
                    url: "default.aspx",
                    beforeSend: function(request) {
                        request.setRequestHeader("Test", "Chenxizhang");
                    },
                    success: function(result) {
                        alert(result);
                    }
                });
            });
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template