The $.get () method of Ajax interacts with the Tomcat server

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.