我打電話的功能,並保存在這個功能我發送一個$。員額爲「upp.php」:JSON解碼未定義指數
function save(){
var oldItems = JSON.parse(localStorage.getItem('itemsArray')) || [];
var newItem = {};
var num = document.getElementById("num").value;
newItem[num] = {
"methv": document.getElementById("methv").value
,'q1': document.getElementById("q1").value,
'q2':document.getElementById("q2").value,
'q3':document.getElementById("q3").value,
'q4':document.getElementById("q4").value,
'comm':document.getElementById("comm").value
};
oldItems.push(newItem);
localStorage.setItem('itemsArray', JSON.stringify(oldItems));}
$.post('upp.php',{ items: JSON.stringify(oldItems) }, function(response) {
在upp.php我使用:
<?php
$array = json_decode($_POST['items'], True);
foreach ($array as $key=>$line) {
}
?>
,但我「項目」
編輯剛開了一個未定義指數:
我所得到的響應張貼後<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css.css" media="all">
<meta name="viewport" content="initial-scale=1.0"/>
<script src="alan.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<title>Data Collection</title>
</head>
<body>
<!--Wrapper-->
<div id="wrap">
<!--Header-->
<div id="header">
<h1> Data Collection </h1>
</div>
<div id="menu">
<ul>
<li><a href="homepage.php">Home</a></li>
<li><a href="comment.php">Comments</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</div><input type="text" id="data"/>
<div id="heading">
<h3> Welcome, alan </h3>
</div>
array(1) {
["items"]=>
string(167) "[{"1173627548":{"methv":"dont know","q1":"-","q2":"-","q3":"U","q4":"-","comm":""}},{"1173627548":{"methv":"dont know","q1":"-","q2":"-","q3":"U","q4":"-","comm":""}}]"
}
<div id="footer">
<h1> Footer </h1>
</div>
</div> <!--End of wrapper-->
</body>
</html>
是的,我得到這一切,但信息是有,但它也顯示其他信息
並把__var_dump($ _ POST); __在upp.php中輸出什麼? – Waygood 2013-03-15 16:28:59
出來陣列(0){} – Bash 2013-03-15 16:42:42
所以你的帖子是空的。看看@Quentin關於重定向的說法。你應該看看你的$ .post – Waygood 2013-03-15 16:51:33