Re: Populating Data Using Server-Side Code?

101 views
Skip to first unread message

asgallant

unread,
Jul 2, 2012, 11:14:02 AM7/2/12
to google-visua...@googlegroups.com
The problem is likely that you are missing jQuery.  The example assumes you have a local copy, which you probably don't.  Switch this line:

<script type="text/javascript" src="jquery-1.6.2.min.js"></script> 

to this:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 

Also, depending on your server settings, you may need to add headers to the getData.php file.  If the above change doesn't fix it for you, add these lines to getData.php before the "echo $string;" line:

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

The first two prevent the browser from caching the result and are not strictly necessary for this to work, but you will want them if the data is likely to change over time.  The third line tells the server and browser that this is json, not HTML, and to interpret it appropriately.

On Friday, June 29, 2012 4:46:33 PM UTC-4, Bob Zinc wrote:
https://developers.google.com/chart/interactive/docs/php_example

I am working on a small project to pull in some information from a website and generate some chart.
However, in beginning, I met some problems: the link above is very clear and I copy to my amazonaws.com server because this code snippet uses PHP to populate a datatable.
What I did is to create three files

exampleUsingPHP.html

getData.php

sampleData.json

and store them into one directory.

But when I accessed the "exampleUsingPHP.html", no desired result showed up.

I guess something wrong with jQuery function ajax()
url, but I cannot figure out where I went wrong.

Can Somebody help me with this question otherwise I cannot go further on my own project.


Thanks a lot!

asgallant

unread,
Jul 2, 2012, 11:16:31 AM7/2/12
to google-visua...@googlegroups.com
BTW, the docs should probably be changed to reflect this, as we get a fair number of people posting "this doesn't work!"

Bob Zinc

unread,
Jul 2, 2012, 11:57:25 AM7/2/12
to google-visua...@googlegroups.com
@asgallant, Thanks a lot.
I only thought something wrong with JQuery version, and replaced it with a one from JSON official website. Thank you for pointing out where I went wrong.
Reply all
Reply to author
Forward
0 new messages