当页面被重定向而不是直接调用时,为什么jQuery getJSON函数不执行? [英] Why doesn't jQuery getJSON function execute when a page is redirected instead of called directly?

查看:115
本文介绍了当页面被重定向而不是直接调用时,为什么jQuery getJSON函数不执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSP页面,该页面随后调用了几个jQuery.getJSON()函数.我绘制了一些图表,所有工作都很好.用户单击菜单项(URL)来调用此JSP页面.

I have a JSP page which calls several jQuery.getJSON() functions subsequently. I render some charts and all works very well. The user clicks on a menu item (URL) to invoke this JSP page.

getJSON函数和处理脚本在$(document).ready(function()...

The getJSON functions and processing scripts execute within $(document).ready(function()...

但是,当用户登录后重定向到同一页面时,该功能将无法执行.我想我肯定缺少有关Ajax或jQuery的基本知识,但是在浏览了几个小时后,我找不到答案.

However when the user is redirected to the same page after logging in, the functions won't execute. I think I must be missing something fundamental with regard to Ajax or jQuery, but I cannot find an answer after several hours of trawling the web.

这是JSP文件:

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ page import="org.apache.struts.Globals" %>
    <%
    /*
    * Dashboard Main Page
    *
    * Version History:
    *
    * Initial version.      
    *
    */
    %>      

<html:html locale="true">

<%@include file="/pages/include_skillsauction_header.html"%>

<body>

<head>
    <script language="javascript" type="text/javascript">

      function changeDivHTML()
      {
        document.getElementById('chart-container-1').innerHTML = "<img src='/apvbase/img/ajax-loader.gif'/>";
      }   
    </script>

<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../js/highcharts.js"></script>
<script type="text/javascript" src="../../js/themes/grid.js"></script>

<script>
$(document).ready(function()
{  
 $(function() 
 { 

 // ---
   $.getJSON('../../JScriptUtils.do?method=getProjectRisks', function(arr)
   {
      chartRisks = new Highcharts.Chart({
         chart: {
            renderTo: 'chart-container-1',
            defaultSeriesType: 'column',
            borderWidth: 2
      },
    title: {
            text: 'Project Risk Profile'
      },
    subtitle: {
         text: 'All Open Risks by Project'
      },
    tooltip: {
         formatter: function() {
            return ''+
               this.x +': '+ this.y +' logins';
         }
      },
    xAxis:
    {
        categories: arr.name,
        labels: {
                rotation: -45,
                align: 'right',
                style: {
                    font: 'normal 8px Verdana, sans-serif'
            }
    }},       
    yAxis: {
                min: 0,
                max: 50,
                title: {
                    text: 'Risks'
                 },
                tickInterval: 10
            },
      series: [
      { data: arr.data,
          dataLabels: {
                enabled: true,
                formatter: function() {
                 return this.y;
                }
            },
        name: 'Risks Raised'
     }
         ]
      });
   });

 // +++
 }); // function()
}); // ready()

</script>  
</head>
<div id="document">

  <%@include file="/pages/include_recruiter_header.jsp"%>

 <div id="main">

  <div id="content-section">
      <div id="contentsNoSideBar">
        <!-- Display Login details -->

        <h2><bean:message key="recruiter.provFeedback.heading"/></h2>           
    <p>
    <table>
     </tr>
      <td>
        <div id="chart-container-1" style="width: 34%; height: 300px"></div>
      </td>
     </tr>
    </table>
      </div>
  </div>
 </div>
 <div id="siteInfo"> 
      <%@include file="/pages/include_standard_footer.jsp"%>
 </div>
</div> 

<script>
 // Display the spinner icon until ready ..
    changeDivHTML();
</script>
</body>

</html:html>

非常感谢您的帮助.

推荐答案

好-是的,因为上下文路径被硬编码.为了解决这个问题,我用src="<%=request.getContextPath()%>/js/jquery.js">

Ok - yes it's because of the context path being hardcoded. To fix this I replaced any reference like ../js/jquery.js with src="<%=request.getContextPath()%>/js/jquery.js">

现在可以了..希望我没有浪费任何时间.

Now it works..hope I didn't waste anyone's time.

这篇关于当页面被重定向而不是直接调用时,为什么jQuery getJSON函数不执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆