我想分配新的位置但不知何故我不能。我这样做时出错了。 这是我的代码
jQuery.ajax({
type: "POST",
data: 'name='+ countryname,
url: "master/ValidationCountry.jsp",
// cache: false,
async: false,
success: function(response){
window.location.assign(request.getContextPath() +"/jsp/admin/AdminMaster.jsp?a=1");
// window.location.reload();
// window.location.replace(request.getContextPath() +"/jsp/admin/AdminMaster.jsp?a=1");
check = true;
},
error: function() {
check=false;
}
});
我得到的错误是: ReferenceError:未定义请求
请帮助我。
答案 0 :(得分:0)
看起来您正在尝试使用javascript访问http servlet requst对象。
request.getContextPath()
是服务器端对象,在客户端不可用。
这里的一个可能的解决方案是使用像_context = <context-path-from-request>
这样的全局变量并在脚本中使用它
这需要在您的视图文件中完成,如jsp / velocity / freemarker / tiles
答案 1 :(得分:0)
jQuery.ajax({
type: "POST",
data: 'name='+ countryname,
url: "master/ValidationCountry.jsp",
// cache: false,
async: false,
success: function(response){
window.location.assign(response.d +"/jsp/admin/AdminMaster.jsp?a=1");
// window.location.reload();
// window.location.replace(response.d +"/jsp/admin/AdminMaster.jsp?a=1");
check = true;
},
error: function() {
check=false;
}
});
....................
并从服务器端Web服务功能
[webMethod]
public static string fun()
{
return httpcontext.current.request.getContextPath();
}