在我的JS中我想从sqlite3 dbase读取数据。这是ajax
代码:
function getHeaterCfg(rDate){
var data = {
isDateRequested : 1,
reqDate : rDate
};
var jData = JSON.stringify(data);
alert(jData);
$.ajax({
url: 'getLatestCfgHeater.php',
type: 'POST',
dataType: 'json',
data: {'querySettings': jData},
success: function(data) {
console.log("success");
//parse data
}
});
}
这里是php代码:
<?php
function var_error_log( $object=null ){
ob_start(); // start buffer capture
var_dump( $object ); // dump the values
$contents = ob_get_contents(); // put the buffer into a variable
ob_end_clean(); // end capture
error_log( $contents ); // log contents of the result of var_dump( $object )
}
$db = new SQLite3('./../../yyyy/config.db');
$jsonData = json_decode($_POST['querySettings']);
var_error_log(json_decode($jsonData));
$isDateRequested = $jsonData->isDateRequested;
if ($isDateRequested == True) {
$date = $jsonData->reqDate;
$stmt = $db->prepare('Select * from cfgs where date like \'(?)%\'');
$stmt->bindValue(1, $date);
}
else {
$stmt = $db->prepare('Select * from cfgs');
}
$resSql = $stmt->execute();
var_error_log($resSql);
echo json_encode($resSql);
?>
这里是php error.log:
[Thu Jan 07 14:37:37 2016] [error] [client xxxx] PHP Warning: json_decode() expects parameter 1 to be string, object given in /var/www/fullcalendar-1.5.3/demos/getLatestCfgHeater.php on line 15, referer: http://xxxx/fullcalendar-1.5.3/demos/sel3.html
[Thu Jan 07 14:37:37 2016] [error] [client xxxx] NULL\n, referer: http://xxxx/fullcalendar-1.5.3/demos/sel3.html
[Thu Jan 07 14:37:37 2016] [error] [client xxxx] object(SQLite3Result)#4 (0) {\n}\n, referer: http://xxxx/fullcalendar-1.5.3/demos/sel3.html
[Thu Jan 07 14:37:37 2016] [error] [client xxxx] PHP Notice: Undefined index: querySettings in /var/www/fullcalendar-1.5.3/demos/getLatestCfgHeater.php on line 13, referer: http://xxxx/fullcalendar-1.5.3/demos/sel3.html
[Thu Jan 07 14:37:37 2016] [error] [client xxxx] NULL\n, referer: http://xxxx/fullcalendar-1.5.3/demos/sel3.html
[Thu Jan 07 14:37:37 2016] [error] [client xxxx] PHP Notice: Trying to get property of non-object in /var/www/fullcalendar-1.5.3/demos/getLatestCfgHeater.php on line 16, referer: http://xxxx/fullcalendar-1.5.3/demos/sel3.html
[Thu Jan 07 14:37:37 2016] [error] [client xxxx] object(SQLite3Result)#3 (0) {\n}\n, referer: http://xxxx/fullcalendar-1.5.3/demos/sel3.html
我应该使用GET方法而不是POST吗? 为什么php端的json_decode抱怨?
chorme说
jData = "{"isDateRequested":1,"reqDate":"7-1-2016"}"
所以我认为它的有效json
格式......
你能指点我怎样才能得到这些数据? Reagrds J.