ajax!!!! of the native
I am a beginner novice, do not like to spray!! The wrong place please the great God teach you!! Thank you!!!
Note the use of post and get is a bit different!!!
///1, Get XMLHttpRequest object
var XMLHttpRequest;
if (window. ActiveXObject) {//Determine if it is IE browser
//Get XMLHttpRequest Object
XMLHttpRequest = new ActiveXObject ("Microsoft.XMLHTTP");
}else{//non-IE browser
//Get XMLHttpRequest Object
XMLHttpRequest = new XMLHttpRequest ();
}
///4, call callback event, determine request status
Xmlhttprequest.onreadystatechange = function () {
/*
xmlhttprequest.readystate Judging Request status
0: The request was not initialized (open () has not been called yet).
1: The request has been established but has not yet been sent (the Send () has not been called).
2: The request has been sent, is in process (usually can now get the content header from the response).
3: The request is in process, and some of the data in the response is usually available, but the server has not finished generating the response.
4: The response is complete; you can get and use the server's response.
*/
if (xmlhttprequest.readystate = = 4) {
//xmlhttprequest.status = = 200 indicates normal return
if (xmlhttprequest.status = =) {
alert ("Request succeeded!!!!" ")
}
}
}
//2, send a request
/*
The first parameter is the way it is requested
The second parameter is the requested address. If you need to pass parameters, just spell it right behind the URL.
The third parameter is whether Async is required or false is not required async true is the need for asynchronous
The fourth argument is that username does not give
The fifth argument is that password does not give
*/
Xmlhttprequest.open ("Get", "url", false);
//This is a post submission method that requires a get submission method not required (this is a different place for post and get)
Xmlhttprequest.setrequestheader ("Context-type", "application/x-www-form-urlencoded");
///3, transfer parameters
//get Request Method
//xmlhttprequest.send (null);
//post Request Method
xmlhttprequest.send ("username=xxx&password=123");
The ajax!!! of jquery
Link Jquery-3.2.0.min.js is required before use.
<script type= "Text/javascript" src= "Js/jquery-3.2.0.min.js" ></script>
<script type= "Text/javascript" >
$.ajax ({
//Request the way post, get
type: "Get",
//Whether asynchronous is required, false does not require async, and true is required for asynchronous
Async: "false",
//The requested path
URL: "url",
//pass-through parameters
data: "Username=zhangsan&password=123",
//Return value type text denotes plain text type
dataType: "Text",
//Call callback function
success:function (data) {
alert (data);
}
});
The use of native Ajax and jquery Ajax