Javascript 我无法将JSON数据数组从php页面检索到其他页面
有人能帮帮我吗?? 我尝试使用jquery ajax解决这个问题,这是一样的,这就是为什么我尝试只使用javascript来解决这个问题Javascript 我无法将JSON数据数组从php页面检索到其他页面,javascript,php,json,Javascript,Php,Json,有人能帮帮我吗?? 我尝试使用jquery ajax解决这个问题,这是一样的,这就是为什么我尝试只使用javascript来解决这个问题 function validateForm() { var q = document.forms["form1"]["question"].value; var T = document.forms["form1"]["title"].value; if (T == null || T == ""
function validateForm()
{
var q = document.forms["form1"]["question"].value;
var T = document.forms["form1"]["title"].value;
if (T == null || T == "")
{
alert("please type you form title first");
return false;
}
if (q == null || q == "")
{
document.getElementById("question").style.color="black";
alert("please enter your question");
return false;
}
question.push(q);
//alert(JSON.stringify(question));
var xhr = new XMLHttpRequest();
xhr.open('post', 'create_form.php',true);
// Track the state changes of the request
xhr.onreadystatechange = function(){
// Ready state 4 means the request is done
if(xhr.readyState === 4){
// 200 is a successful return
if(xhr.status === 200){
alert(xhr.responseText); // 'This is the returned text.'
}else{
alert('Error: '+xhr.status); // An error occurred during the request
}
}
}
// Send the request to send-ajax-data.php
xhr.send({myData:JSON.stringify(question)}); //+encodeURI(JSON.stringify(question))
// addField();
return true;
}
而不是这个
$json = file_get_contents('php://input');
$obj = json_decode($json, TRUE);
您是否检查过ajax请求发送的firebug或chrome开发控制台??请在服务器端执行var_dump$\u POST或print_r$\u POST以了解是否包含数据。是的,我做了这两件事,但当我提醒值alertJSON.stringifymyData:JSON.stringifyquestion;它给我的html代码,我在网页上!!!!!!
$json = file_get_contents('php://input');
$obj = json_decode($json, TRUE);
$data = json_decode($_POST['myData']);
$array=json_decode($_REQUEST['question']);
if(isset($_POST['myData'])){
$obj = json_decode($_POST['myData']);