ajax
  • jquery
  • 2013-06-21 46 views 0 likes 
    0

    我想分配新的位置,但不知何故我不能。我在做这件事时遇到了一个错误。 这里是我的代码使用window.location.assign()时出现错误

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

    plz帮助我。

    +0

    尝试使用$ {request.contextPath}而不是request.getContextPath()作为请求不是客户端变量。 –

    回答

    0

    它看起来像你试图访问一个HTTP servlet请求对象使用JavaScript。

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

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

    这就需要像JSP /速度/ freemarker的视图文件来完成/瓦

    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(); 
    } 
    
    相关问题