我想分配新的位置,但不知何故我不能。执行此操作时出现错误。以下是我的代码
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: request
请帮帮我。
发布于 2013-06-21 13:12:56
看起来您正在尝试使用javascript访问http servlet请求对象。
request.getContextPath()是一个服务器端对象,在客户端是不可用的。
一种可能的解决方案是使用全局变量,如_context = <context-path-from-request>,并在脚本中使用它
这需要在视图文件中完成,比如jsp/tiles/freemarker/tile
发布于 2013-06-21 14:17:23
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();
}https://stackoverflow.com/questions/17228086
复制相似问题