ajax Setup header Guide tutorial
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!
- ajax request to add custom header parameter code
- A summary of how to set and get custom header information using ajax
- Springboot solves the cross-domain request problem of ajax+ custom headers
- php gets the ajax headers method and the content instance
- jQuery.Form enables you to set headers when uploading files with Ajax
- jQuery.ajax cross-domain request webapi set headers solution
- ajax post form submission setRequestHeader error resolution
Related article
-
Do-it-yourself ajax encapsulation
After the project development is more intense, a long time did not write an article. Fortunately, the project has entered the late stage of testing and implementation, and I can have time to summarize some of my experience in recent projects. Since the introduction of WEB2.0 rich client, AJAX technology is now more and more popular, waiting to replace the trend of CS desktop applications.2009-07-07 -
AJAX Chinese garbled PHP perfect solution
AJAX Chinese garbled code problem, after an afternoon of efforts finally perfect solution, now write down the experience, hope to help those who are still trapped in this problem and headache2012-09-09 -
Return a method of html concatenation string filling data via ajax in the layer pop-up layer
This article mainly introduces the method of returning html concatenation string filling data through ajax in the layer pop-up layer. This article introduces it in great detail through the example code, which has certain reference value, and the friends who need it can refer to it2018-11-11 -
AJAX request differentiates $_SERVER[" "HTTP_X_REQUESTED_WITH"]
Many people know about this content. But from what I've searched for, they're just looking at it, they have no idea what's going on inside.2011-06-06 -
ajax technology to make online lyrics search function
ajax technology to make online lyrics search function...2006-09-09 -
Ajax jsonp cross-domain request implementation method
This article mainly introduces the Ajax jsonp cross-domain request implementation method of the relevant information, need friends can refer to the next2015-11-11 -
Ajax to pass Chinese parameters to the background garbled effective solution
Use Ajax to pass Chinese parameters, if the parameters are not processed, it will become garbled in the background, the solution is very simple, the need for friends can refer to this article2014-05-05 -
Keep the AJAX page state in mind
When AJAX was popular, a lot of information was AJAX asynchronous requests, such as clicks, page turns, and so on. Usually when you refresh the browser, the current page resets to its original state. Not to mention sending the url to your friends. Below to share the realization of ideas, let's have a look2017-03-03 -
ajax agent, automatically determine the character encoding
ajax agent, automatically determine the character encoding...2006-11-11
Latest comments