Summary of the AJAX request path under Tomcat

Source: Internet
Author: User

There are two types of Ajax URLs, one is absolute and the other is a relative path.

  Absolute path: includes the full request path of the protocol name, host address, port, Web project name, and so on. For example: $.ajax ({    URL: "Http://localhost:8080/webname/test"});  Benefits: For example, Ajax in a Weba project needs to request services from a Webb project, You must use an absolute path. Cons: Using an absolute path requires the name of an ancient geographic Web project, and if the Webb Project is renamed, the corresponding Ajax request needs to be modified.   Two, relative path: No protocol name, host address, port, Web project name, only the requested path is required. Assumption: Project path: Http://localhost:8080/webname page path:/webname/index.html (Page a),/webname/test/test.html (page b) Request path:/request/ Ajaxtest,request/ajaxtest 1, if the request path begins with a root path, whatever Ajax is on the page, the request is relative to the root path of the server, and the final request path is: http://localhost:8080/ Request/ajaxtest For example: $.ajax ({    URL: "/request/ajaxtest"}); the reason: Starting with "/" is to indicate that the request is based on the root path from the server, that is, the path that is not relative to the HTML.  2, if the request does not start with a root path (common), then the request path is relative to the path where the HTML resides.     a, if requested on page A, the final request path is: Http://localhost:8080/webname/request/ajaxtest.    //     /webname/index.html page     $.ajax ({        URL: "Request/ajaxtest"     });    reason: The index.html page corresponds to a path of "/webname/", So the URL following this path is the final request path.      B, if requested on page B, the final request path is:/httpLocalhost:8080/webname/test/request/ajaxtest.    //    /webname/test/test.html page     $.ajax ({        URL : "Request/ajaxtest"     });    Cause: The path to the test.html page is "/webname/test/", so the URL should be followed by the Test level.   Environment Description Web server: Tomcat7mvc frame: Springmvc above content, are based on the environmental testing self-summed up, and there is no theoretical basis, if there are errors please leave a message.

The AJAX request path summary under Tomcat

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.