使用 JQuery 进行 Spring MVC 和 Ajax 操作
我有一个名为 CreateProcessGroup.jsp 的 JSP 页面,并且使用注释控制器将对 CreateProcessGroup.htm 的请求映射到该页面。但是当我从浏览器请求页面时,我遇到了一个有趣的问题,它可以工作,当使用 jQuery $.get 方法发送请求时,我得到 404(CreateProcessGroup.htm 未找到)两个请求之间有区别吗?
我的 JSP 页面位于 WebContent 目录下,JS 文件位于 WEBContent/Jquery 下,我的函数发送如下请求:
function SendCreateProcessGroupRequest()
{
var pid = $('#pid').val();
var description = $('#processGroupDescription').val();
var x = "/CreateProcessGroup.htm";
alert(x);
$.get(x, { pid: 62, description: description },
function(data){
alert("Data Loaded: " + data);
});
}
我需要将 URL 指定为 ../CreateProcessGroup.htm
吗?事实上我尝试过:
- /CreateProcessGroup.htm
- ../CreateProcessGroup.htm
- /../CreateProcessGroup.htm
- ../../CreateProcessGroup.htm
- /../../CreateProcessGroup.htm
我的猜测是 DispatcherServlet 无法将 Ajax 请求映射到控制器,但这很愚蠢,不是吗?
我怎样才能摆脱这种情况?
谢谢大家。
I have a JSP page called CreateProcessGroup.jsp and I use an annotation controller to map requests to CreateProcessGroup.htm to that page. But I'm having an interesting issue when I request the page from browser it works, when send a request using jQuery $.get method I get 404 (CreateProcessGroup.htm not found) is there a difference between two requests?
My JSP page just under WebContent dir and JS file under WEBContent/Jquery my function sending the request like below:
function SendCreateProcessGroupRequest()
{
var pid = $('#pid').val();
var description = $('#processGroupDescription').val();
var x = "/CreateProcessGroup.htm";
alert(x);
$.get(x, { pid: 62, description: description },
function(data){
alert("Data Loaded: " + data);
});
}
Do I need to give the URL as ../CreateProcessGroup.htm
? Indeed I tried:
- /CreateProcessGroup.htm
- ../CreateProcessGroup.htm
- /../CreateProcessGroup.htm
- ../../CreateProcessGroup.htm
- /../../CreateProcessGroup.htm
My guess is DispatcherServlet can not map Ajax requests to Controllers but this is stupid isn't it?
How can i get rid of the situation?
Thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样做:
如果您请求的页面位于发出请求的页面旁边,则不需要前面的路径,它会(默认情况下)向同一路径发出请求,仅在末尾带有该页面/处理程序。
Try this instead:
If the page you're requesting is beside the one making the request there's no need for a path in front, it will (by default) make a request to the same path just with that page/handler on the end.