J'ai fait ma lecture, j'ai trouvé aucune erreur, mais le php, json et jquery jouent bien ... quelqu'un peut-il voir quelque chose que je ne vois pas dans ce code pour cela? travailler ?PHP, JSON, et JQUERY
Mon fichier clickdates.php a 3 valeurs que json shpould peut faire en 1 appel ... mais ce n'est pas le cas ... Voici le fichier php (et quand je le teste, j'ai 3 valeurs et le 3 id qui devrait se connecter dans le jquery) .. Pouvez-vous voir quelque chose de mal que je ne sais pas ??
<?php
$choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d");
$con = mysql_connect("localhost","root","xxxxxx");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("inverters", $con);
$sql = "SELECT sum(power/1000) AS choice FROM feed WHERE date = '".$choice."' group by date"; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error());
$row = mysql_fetch_assoc($res);
$dayPowerP = array($row['choice']);
?>
<?php
$choice = (isset($_POST['choice'])) ? date("m",strtotime($_POST['choice'])) : date("m"); $con = mysql_connect("localhost","root","xxxxxx");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("inverters", $con);
$sql = "SELECT sum(power/1000) AS choice FROM feed WHERE month(date) = '".$choice."'";
$res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error());
$row = mysql_fetch_assoc($res);
$monthPowerP = array($row['choice']);
?>
<?php
$choice = (isset($_POST['choice'])) ? date("Y",strtotime($_POST['choice'])) : date("Y"); $con = mysql_connect("localhost","root","xxxxxx");
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("inverters", $con);
$sql = "SELECT sum(power/1000) AS choice FROM feed WHERE year(date) = '".$choice."'";
$res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error());
$row = mysql_fetch_assoc($res);
$yearPowerP = array($row['choice']);
?> <?php
$outarr['dayPowerP'] = $dayPowerP;
$outarr['monthPowerP'] = $monthPowerP;
$outarr['yearPowerP'] = $yearPowerP;
echo json_encode($outarr);
?>
Voici ce que ma sortie de test est à partir du fichier php ... à mes yeux, il devrait fonctionner ... mais il ne le font pas.
{"dayPowerP":["12.7240"],"monthPowerP":["145.0460"],"yearPowerP":["941.0370"]}
Voici le jquery très simple qui devrait être Puting les valeurs où ils appartiennent du JSON ... mais pas de chance ...
$(document).ready(function() {
$('#datepicker').datepicker({maxDate: 0, dateFormat: 'yy-mm-dd', onSelect: function(dateText) {
var myDate = $(this).datepicker('getDate');
$('#apDiv1').html($.datepicker.formatDate('DD, d', myDate));
$('#apDiv5').html($.datepicker.formatDate('MM', myDate));
$('#apDiv7').html($.datepicker.formatDate('yy', myDate));
$.ajax({
type: "POST",
url: "clickdates.php",
data: {choice: dateText},
dataType: "json",
success: function(json_data) {
$('#apDiv2').html(json_data['dayPowerP']);
$('#apDiv6').html(json_data['monthPowerP']);
$('#apDiv8').html(json_data['yearPowerP']);
}
})
}});
});
Qu'est-ce que je ne vois pas ici ??
Alan
Pourquoi y a-t-il des crochets autour des nombres dans la sortie JSON? Cela donne l'impression que ce sont des tableaux JavaScript à entrée unique plutôt que des valeurs. Pouvez-vous charger un débogueur JavaScript dans votre navigateur favori et regarder json_data après qu'il a été retourné à votre réponse AJAX pour vérifier cela? –
C'est la vue en direct dans dreamweaver, pour voir si j'ai une sortie du fichier php – hkalan2007