Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9164479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:41:37+00:00 2026-06-17T14:41:37+00:00

This is two questions in one, the actual state of my code is this:

  • 0

This is two questions in one, the actual state of my code is this:

<script type="text/javascript">
init_ui();
function init_ui() {

        $("[rel='tooltip']").tooltip();

        $(".ajax_link").live("click",function(){
            id = $(this).attr("id");
            jQuery("#ajax_div").html('<img src="../../../../bundles/donepunctis/img/loading.gif" alt="loading...">');
            jQuery.ajax({
                url: '<?= $view['router'] -> generate('done_punctis_ajax_detail_data_url'); ?>' + '?id=' + id,
                success:function(result){
                    jQuery("#ajax_div").html('');
                    //alert(data);
                    chart.draw(data, options);
                }
     });
        })
}

var data;
var options;
var chart;

      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(drawChart);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart() {

        // Create the data table.
        data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'Slices');
        data.addRows([
          ['Mushrooms', 3],
          ['Onions', 1],
          ['Olives', 1],
          ['Zucchini', 1],
          ['Pepperoni', 2]
        ]);

        // Set chart options
        options = {'title':'How Much Pizza I Ate Last Night',
                       'width':400,
                       'height':300};

        // Instantiate and draw our chart, passing in some options.
        chart = new google.visualization.PieChart(document.getElementById('ajax_div'));

      }
</script>

At the moment im just ignoring the return from the ajax call, using the data to the chart somministrated hard coded on the var data.

  1. how should look my echo on the php side to return the same value I’m using right now, but passed from the ajax return?

  2. this code is working fine the first time, but if try to click again ajax_link the ajax call is fired but the google chart code doesn’t do anything. Why is that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:41:38+00:00Added an answer on June 17, 2026 at 2:41 pm

    This code is working fine the first time, but if try to click again ajax_link the ajax call is fired but the google chart code doesn’t do anything. Why is that?

    Look at the success callback from your $.ajax call:

    jQuery.ajax({
      url: '<?= $view['router'] -> generate('done_punctis_ajax_detail_data_url'); ?>' + '?id=' + id,
      success:function(result){
      jQuery("#ajax_div").html('');
        chart.draw(data, options);
      }
    });
    

    You are calling chart.draw(data, options);, which simply redraws the chart with the data you last populated it with.

    You probably want to call drawChart and pass in the new data:

    jQuery.ajax({
      url: '<?= $view['router'] -> generate('done_punctis_ajax_detail_data_url'); ?>' + '?id=' + id,
      success:function(result){
      jQuery("#ajax_div").html('');
        drawChart(data);
      }
    });
    

    Then in drawChart you can populate the chart with your new data:

    function drawChart(myData) {
      // Create the data table.
      data = new google.visualization.DataTable();
      data.addColumn('string', 'Topping');
      data.addColumn('number', 'Slices');
      if(myData) {
        // TODO: add rows based on myData
      } else {
        data.addRows([
          ['Mushrooms', 3],
          ['Onions', 1],
          ['Olives', 1],
          ['Zucchini', 1],
          ['Pepperoni', 2]
        ]);
      }
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is two questions in one, so here we go. I have a simple
This is a follow-up to two questions on representation types, which are type parameters
This question has two parts (maybe one solution?): Sample vectors from a sparse matrix
This is kinda....a two part question. The first one is much more important than
Note: this question is related to this one , but two years is a
This is an extension of this question: SQLite problem selecting two columns as one
As a followup to this two questions and its answers Question 1 and Question
This consists of two questions: Is MySQL's timestamp field really faster than datetime field
This is really two questions: Why isn't the membership operator (__contains__) ever being called?
There are two questions to this: How can I best spread the word about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.