开发者

Why doesn't jQuery getJSON function execute when a page is redirected instead of called directly?

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.

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

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.

Here's the JSP file:

<%@ 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: {
  开发者_StackOverflow社区       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>

Any help is greatly appreciated.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜