jquery - How to query function from ajax call? -


i want draw google chart, query written in function in ajax.php file. chart in different php file calling json data using ajax.

i want call function in php file, joblocation().

function joblocation(){  global $db;  //query location total post $sql = 'select ljl.location_id, count(ljj.job_id) count, ljl.location_name {local_jobs_job} ljj inner join {local_jobs_location} ljl on ljj.job_location = ljl.location_id ljj.job_type = 0 group ljl.location_name';   //get query record $data = $db->get_records_sql($sql);  //put query array $rows = array();  $rows = array_map(function($item) { return (object) ['c' => [     (object) ['v' => $item->location_name, 'f' => null],     (object) ['v' => intval($item->count), 'f' => null] ]]; }, array_values($data));    // prepare return data $cols = [ (object) ['id' => '', 'label' => 'label', 'pattern' => '', 'type' => 'string'], (object) ['id' => '', 'label' => 'total', 'pattern' => '', 'type' => 'number'], ];  $returndata = new stdclass; $returndata->cols = $cols; $returndata->rows = $rows;  echo json_encode($returndata); } 

this ajax call call function.

 var jsoncolumnchartdata = $.ajax({                             url: "ajax.php",                             contenttype: "application/json",                             data: {action: 'joblocation'},                             datatype: "json",                             async: false                             }).responsetext; 

is correct way?

i tried this:

var jsonpiechartdata = $.ajax({                             url: "ajax.php",                             contenttype: "application/json",                             data: {},                             datatype: "json",                             async: false,                             success: function(result){                                 joblocation(result);                                 },                             error: function() {                                 alert('error occured');                                 }                             }).responsetext; 

when run, error pop appear. doesn't function.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -