Home > Web Front-end > JS Tutorial > body text

How to write the url path of ajax?

藏色散人
Release: 2019-05-06 11:56:54
Original
9751 people have browsed it

How to write the url path of ajax?

How to write the url path of ajax?

For example, your page path is: http://localhost:8080/projectname/resource/index.html

The .do added at the end of the url request is for the server to distinguish whether the request is a static resource or a static resource. servlet request (.do followed by is a servlet request)

1. You can start with "/" relative to the root directory of the website (the root directory refers to the root directory of the server, not the root directory of your project)

$.ajax({
    url:"/getData.do"
})
Copy after login

The requested path is:

http://localhost:8080/getData.do
Copy after login

2. "../" indicates the upper-level directory of the page directory

$.ajax({
    url:"../getData.do" 
})
Copy after login

The requested path is:

http://localhost:8080/projectname/getData.do
Copy after login
Copy after login

3. The root path of the project

$.ajax({
    url:"getdata.do" 
})
Copy after login

and the requested path is:

http://localhost:8080/projectname/getData.do
Copy after login
Copy after login

4. The full path

$.ajax({
    url:"http://localhost:8080/projectname/getdata.do" 
})
Copy after login

and the requested path is:

http://localhost:8080/projectname/getdata.do
Copy after login

springMVC If The request mapping is written like this

How to write the url path of ajax?

If we want to request the register method, the url: ../user/register.do is written like this

Because the page path That's it

http://localhost:8080/projectname/resource/index.html
Copy after login

Just let the servlet mapping request follow the project path

http://localhost:8080/projectname.

The final requested path is

http://localhost:8080/projectname/user/register.do
Copy after login


The above is the detailed content of How to write the url path of ajax?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template