好的,这个问题已被多次询问,但我查看了所有这些答案并试图做他们所说的无济于事。根据我读过的所有帖子以及我所知道的一切都应该有效,我不知道为什么不这样做。我有一个脚本运行一些javascript解析名称到一个数组。然后我试图通过ajax将该数组发送到php服务器,以便我可以在php中获取这些变量。我看了谷歌调试器,它发布很好,但当我尝试通过$ _POST ['name']访问变量时,没有任何显示。当我执行if以检查是否使用isset设置名称时也没有任何事情发生。我在这里完全不知所措。这是代码。它显示开始和结束但不显示中间。我在这方面花了太长时间,只是不明白为什么它不起作用。提前谢谢。
<script>
$(function(){
$("#teamSubmit").click(function() {
//Code here
//Loop through all colmns in team div
var teamArray = [];
$("#teams .team .column").each(function(index, element){
//Loop through all items in the column
var $this = $(this);
//console.log($(this));
//console.log("Hello");
thisTeam = '';
$this.children(".portlet").each(function(index1, element){
//thisTeam += ($(this).find(".portlet-header").text();
//console.log("Inside .portlet");
//console.log('Length =' + ($(this).length - 1) + ' Index =' + index1);
if(($this.children(".portlet").length - 1) === index1){
thisTeam += ($(this).find(".portlet-header")).text();
//console.log("New team");
}
else{
thisTeam += ($(this).find(".portlet-header")).text() + ",";
}
});
console.log(thisTeam);
teamArray[index] = thisTeam;
});
//console.log(thisTeam);
//console.log(teamArray);
jsonArray = JSON.stringify(teamArray);
$("#teams").html("");
console.log(jsonArray);
$.ajax({
type: "POST",
url: 'settings.php',
data: {json : jsonArray},
//data: jsonArray,
dataType: 'json',
success: function(data)
{
//alert("success!");
console.log(jsonArray);
}
});
//Grab javascript array and query and update the db
<?php
//echo "console.log('begin '" . isset($_POST['json']) .");";
//$test = $_POST['jsonArray'];
//echo $test;
if(isset($_POST['json'])){
//$array = $_POST['json'];
$teamMembers = json_decode($_POST['json']);
//echo "<script> console.log($teamMembers); </script>";
echo "console.log('middle');";
//echo "$teamMembers";
//Get highest T_ID and increment by 1
//Loop through insert into SEA_TEAMS
//Loop through insert into SEA_TEAM_USER
}
echo "console.log('end');";
?>
});
});