Ajax Ajax = Asynchronous JavaScript and XML.
AJAX is a technique that can update parts of a Web page without reloading the entire page.
Ajax Get () method
Definition and usage
The $.get () method loads data from the server using an HTTP GET request.
Instance
Request "test.php", but ignore the return result:
$.get ("test.php");
Request "test.php" and send some extra data along with the request (ignoring the return result):
$.get ("test.php", {name: "Donald", Town: "Ducktown"});
Request "test.php" and pass an array of data to the server (ignoring the returned results):
$.get ("test.php", {' colors[] ': ["Red", "Green", "Blue"]});
Request "test.php" and alert the result of the request:
$.get ("test.php", function (data) {
Alert ("Data:" + data);
});
Grammar
$.get (url,data,function (DATA,STATUS,XHR), DataType)
Parameters |
Describe |
Url |
Necessary. Specify the URL that you want to request. |
Data |
Optional. Specifies the data that is sent to the server along with the request. |
function (DATA,STATUS,XHR) |
Optional. Specifies the function to run when the request succeeds. Additional parameters:
- Data-contains results from the request
- Status-contains the requested State ("Success", "Notmodified", "Error", "Timeout", "ParserError")
- xhr -Contains XMLHttpRequest objects
|
DataType |
Optional. Specifies the data type of the expected server response. By default, JQuery will be smart to judge. Possible types:
- "XML"-an XML document
- "HTML"-HTML as plain text
- "Text"-Plain text string
- "Script"-Runs the response in JavaScript and returns it as plain text
- "JSON"-runs the response in JSON and returns it as a JavaScript object
- "Jsonp"-load a JSON block with Jsonp and add a "? callback=?" To the URL to specify the callback
|
Interacting with the server servlet
JSP page Script
<script>
/**
* After page load execution
*/
$ (function () {
var date = new Date ();
$.get (' sendview.do ', {
"Date":d ate
},function (data) {
})
})
</script>
The Ajax $.get () method sends a request URL such as HTTP get to the server, can use function (data) to accept the results returned by the server data, on the server side to build a servlet class can accept the GET request and extract user-related information. Specifically, to override a Get method,
Public class Logservlet extends httpservlet {
protected void doget (httpservletrequest req, HttpServletResponse resp) throws Servletexception, IOException {
// get the request/senddata.do
String req_url =req.getservletpath (). substring (1);
System. out. println ("-------------"+req.getservletpath ());}}
Can get the request URL
The $.get () method of Ajax interacts with the Tomcat server