jquery get data from php

Solutions on MaxInterview for jquery get data from php by the best coders in the world

showing results for - "jquery get data from php"
Valeria
02 Jan 2020
1You can read about ajax in javascript and make an ajax request that gets the json object from PHP then process that in your javascript:
2
3Example (with some improvement to your PHP code)
4
5PHP
6  
7$chart6 = $controller->runQuery("SELECT DATE(pay_date) `DATE`, SUM(amount) daily_amount, DATE_FORMAT(pay_date,'%a') DAYNAME FROM tbl_paid WHERE DATE(pay_date) BETWEEN DATE(:today) - INTERVAL 1 WEEK AND DATE(:today) GROUP BY DATE(pay_date);"); 
8$chart6->execute(array(":today"=>$today));
9$labels = array();
10$series = array()
11while($fetch = $stmt->fetch(PDO::FETCH_ASSOC)) {
12  $labels[] = $fetch['DAYNAME'];
13  $series0[] = $fetch['daily_amount'];
14}
15$series[] = $series0;
16
17// add the labels and series to an array, then convert that to json
18$data = array('labels' => $labels, 'series' => $series);
19echo json_encode($data);
20
21JS:
22
23// Make an Ajax request, here I am using jQuery $.getJSON  but you can use $.get or $.post if you need to have it as a post request, or even $.ajax
24
25$.getJSON('https://example.com/database_fetch_page.php', function(data) {
26  new Chartist.Line('#headline-chart', data, options);
27});
similar questions
queries leading to this page
jquery get data from php