$(document).ready(function () {
$(".linkDelete").click(function () {
var userid = $(this).attr("id");
console.debug("saurabh userid", userid);
var url = "/delete?id=" + userid;
var s = "SpringHibernateAnnotations";
console.debug("saurabh url", url);
$.ajax({
url: s + "/delete?id=" + userid,
success: function (data) {
$('#result').html(data);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
我有这个jquery ajax函数生成这个URL GET http:// localhost:8080/SpringHibernateAnnotations/SpringHibernateAnnotations/delete?id = 253 404(Not Found)而不是它应该生成 http:// localhost:8080/SpringHibernateAnnotations/delete? id = 253 404,如果我删除var s ="SpringHibernateAnnotations"; 并将我的url保存在ajax方法中作为url:"/ delete?id ="+ userid,它生成http:// localhost:8080/delete?id = 253,因为我无法进入application.So怎么能我生成这个正确的URL http:// localhost:8080/SpringHibernateAnnotations/delete?id = 253
/在base路径的url之前添加.-
var s= "/SpringHibernateAnnotations";
Run Code Online (Sandbox Code Playgroud)
如果/在开始时不存在则将其视为relative路径.网址将是 - http://localhost:8080/SpringHibernateAnnotations/delete?id=253