HTML section
<input type= ' text ' placeholder= ' user name ' id= ' username ' name= ' username ' class= ' text ' tabindex= ' 1 ' >
<input type= ' text ' placeholder= ' password ' id= "password" name= "pwd" class= "text" tabindex= "2" >
<a javasript://id= "Login" > Login </a>
A landing page requires username and password.
JS section (which wrote some judgments and regular, and so on, this is not explained in detail)
$.ajax ({
Type: "Get",//http request mode, "get": Request data from the specified resource; "POST": submits the data to be processed to the specified resource;
URL: ...,//URL address of the sending request
Data:{username: "username", UserPassword: "UserPassword"},//data to be sent to the server, in the form of a Key/value key-value pair;
DataType: "Text",//expected data type returned by the server
Success:function (Result) {
Location.href = "c-1.html"//callback function after successful request
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {//Call this method when the request fails;
alert (xmlhttprequest.status); Can query the XMLHttpRequest state status
alert (xmlhttprequest.readystate); () The value that pops up (0) uninitialized (1) loading (2) loading complete (3) interaction (4) complete
alert (textstatus); Popup ParserError Returns the wrong data type, which is the value of datatype
Alert (' Read timeout, please check network connection ');
}
})
})
})
Ajax calls background Java