找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 js教程 查看内容

ajax的url路径怎么写?

作者:模板之家 2019-5-6 11:56 4748人关注

比如你的页面路径是:http://localhost:8080/projectname/resource/index.html url请求最后加.do是为了服务器区分这个请求是静态资源还是servlet请求.

ajax的url路径怎么写?

比如你的页面路径是:http://localhost:8080/projectname/resource/index.html

url请求最后加.do是为了服务器区分这个请求是静态资源还是servlet请求(后边有.do就是servlet请求)

1、相对于网站根目录可以用"/"开始 (根目录是指服务器的根目录,不是你项目的根目录)

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

请求的路径是:

http://localhost:8080/getData.do

2、“../”表示页面目录的上一级目录

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

请求的路径是:

http://localhost:8080/projectname/getData.do

3、项目的根路径

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

请求的路径是:

http://localhost:8080/projectname/getData.do

4、全路径

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

请求的路径是:

http://localhost:8080/projectname/getdata.do

springMVC如果是这样写的请求映射

81bfab0ff9ba2f107b36d3df2eee73d.png

如果我们要请求register这个方法,url:../user/register.do这样写

因为页面路径是这样

http://localhost:8080/projectname/resource/index.html

让servlet映射请求跟在项目路径

http://localhost:8080/projectname后面就可以了。

最终请求的路径是

http://localhost:8080/projectname/user/register.do

以上就是ajax的url路径怎么写?的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章!


路过

雷人

握手

鲜花

鸡蛋
来自: [db:来源]

全部回复(0)

发表评论