Home>Article>Web Front-end> How to change header with jquery ajax

How to change header with jquery ajax

藏色散人
藏色散人 Original
2021-12-01 11:31:47 6055browse

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

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!

Statement:
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
Previous article:How to remove tr in jquery Next article:How to remove tr in jquery