Wednesday, July 31, 2019

javascript - Google Visualization API php ajax



I am using this Achieving Google Visualization chart reloads using ajax example to dynamically retrieve data from Mysql database and I get "Uncaught SyntaxError: Unexpected token <" error.
This is my HTML file




















and This is my PHP file test.php







$con = mysql_connect("localhost","userName","password");

if (!$con)

{

die('Could not connect: ' . mysql_error());


}

mysql_select_db("DB_NAME", $con);

$result = mysql_query("call cargosys.rpt_salesByDate('2013/03/05','2013/03/10')");
$output = array();
while($row = mysql_fetch_array($result)) {
// create a temp array to hold the data
$temp = array();


// add the data
$temp[] = $row['inv_no'];
$temp[] = ''' . $row['bl_no'] . ''';
$temp[] = ''' . $row['inv_date'] . ''';
$temp[] = ''' . $row['cust_name'] . ''';
$temp[] = $row['Amount'];

// implode the temp array into a comma-separated list and add to the output array
$output[] = '[' . implode(', ', $temp) . ']';

}

// implode the output into a comma-newline separated list and echo
echo implode(",\n", $output);
//echo json_encode($output);
mysql_close($con);


Answer



Inside the success function do:




console.log(responseData);


Then copy and paste responseData into the JSON validator at jsonlint.com



I am guessing it's a JSON syntax error, which the validator will point out to you.


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...