0

我想分配新的位置,但不知何故我不能。执行此操作时出现错误。这是我的代码

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:请求未定义

请帮助我。

4

2 回答 2

0

看起来您正在尝试使用 javascript 访问 http servlet 请求对象。

request.getContextPath()是服务器端对象,它在客户端不可用。

这里一种可能的解决方案是使用全局变量_context = <context-path-from-request>,并在脚本中使用它

这需要在您的视图文件中完成,例如 jsp/velocity/freemarker/tiles

于 2013-06-21T05:12:56.403 回答
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();
}
于 2013-06-21T06:17:22.737 回答