ajax Setup header Guide Tutorial _AJAX Related _ Scripting Home

ajax Setup header Guide tutorial

Updated: Oct 12, 2023 14:41:48 Author: Let God love you
Ajax is a misleading name,Ajax applications may use XML to transfer data, but the data as plain text or JSON text transfer is just as common, this article gives you the ajax setup header guide tutorial, interested friends take a look at it

What is AJAX?

AJAX = Asynchronous JavaScript And XML.

AJAX is not a programming language.

AJAX simply combines:

XMLHttpRequest object built into the browser (requests data from the web server)

JavaScript and HTML DOM (display or use data)

Ajax is a misleading name. Ajax applications may use XML to transfer data, but it is equally common to transfer data as plain text or JSON text.

Ajax allows Web pages to be updated asynchronously by exchanging data with the Web server behind the scene. This means that parts of a web page can be updated without having to reload the entire page.

Here is the ajax Setup header Guide tutorial, which looks like this:

setting headers

$.ajax({
    headers: {
        Accept: "application/json; charset=utf-8"
    },
    type: "get",
    success: function (data) {
    }
});

beforeSend sets the header

$.ajax({ type: "GET", url: "default.do", beforeSend: function(request) { request.setRequestHeader("Test", "Chenxizhang"); }, success: function(result) { alert(result); }});

$.ajaxSetup() Global Settings Header Request header

// Set the request default $.ajaxSetup({beforeSend: function (xhr) {// Can set a custom Header // token in the header xhr.setRequestHeader('Authorization', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9'); xhr.setRequestHeader('Content-Type', 'application/json'); // application/x-www-form-urlencoded }, complete: function (xhr) {// Set the login intercept if (xhr.responsejson.code == "error_unauth") {console.log(" No login! ") ); layer.msg(" Not logged in! ") ); // location.href="login.html" rel="external nofollow" rel="external nofollow" ; } else {console.log(" Logged in! ") ); }},});

or

// Set the request default value $.ajaxSetup({headers: {// Default request header "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" , "Content-Type": "application/json" } , complete: function (xhr) {// Set the login intercept if (xhr.responsejson.code == "error_unauth") {console.log(" No login! ") ); layer.msg(" Not logged in! ") ); // location.href="login.html" rel="external nofollow" rel="external nofollow" ; } else {console.log(" Logged in! ") ); }},});

This article about ajax setup header is introduced to this, more related ajax setup header content please search the previous article of Script home or continue to browse the following related articles hope that you will support script home in the future!

Related article

Latest comments