我有問題,我想變量$_POST
添加到數組的值。 然後我會將它編碼爲json。但$_POST
變量沒有給出任何價值。 編輯我沒有編輯代碼: 這裏我的代碼:
<?php
$temp = isset($_POST['temp']) ? $_POST['temp'] : '';
$arr["temp_display"] = $temp;
echo json_encode($arr);
,我希望結果會是這樣
{"temp_display": value_of_$temp}
我嘗試用相同的情況,但我想補充的價值$ _POST到MySQL數據庫及其Works。 下面的代碼:
<?php
include("connect.php");
$link=Connection();
$temp=$_POST["temp"];
$query = "INSERT INTO `templog` (`temperature`)
VALUES ('".$temp."')";
mysql_query($query,$link);
mysql_close($link);
?>
編輯這裏我jQuery代碼:
$(document).ready(function() {
setInterval(update, 200);
function update(){
var cache = $('.deneme').children();
$.getJSON('json.php', function(data) {
$('.deneme').text(data.temp).append(cache);
})
}
});
感謝您對烏爾幫助...
'$ arr' ID未定義? – RomanPerekhrest
什麼是你用來檢索日期的jQuery代碼。帖子, –
$ arr [「temp_display」] = isset($ _ POST ['temp'])? $ _POST ['temp']:''; –