【发布时间】:2018-04-28 03:29:26
【问题描述】:
我在分配某个array 变量时遇到了这个问题。当我将 post 它发送到 Codeigniter 控制器时,它会产生此错误 Click to view Image。
查看:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
function submit() {
var TableData = {"table1":"sample1","table2":"sample2","table3":"sample3"};
var Data = JSON.stringify(myTableArray);
$.ajax({
type: "POST",
url: "http://janncomputing/tabulation/judges/save_Production",
data: {pTableData : Data},
success: function(result){ //retrieve data
alert('Success');
alert(result); //alert it
}//success
});
</script>
</head>
<body>
<div>
<button type="button" onClick="submit();">SUBMIT</button>
</div>
</body>
</html>
控制器:
public function save_Production()
{
$table = json_decode($_POST['pTableData'],true);
$msg = $table['table1'];
echo $msg;
}
【问题讨论】:
-
确保您的网址正确
-
是不是你是 JSON.stringify(myTableArray) 而不是 TableData?
-
请参阅this answer,了解如何在 ajax 帖子中发送 Json。
-
兄弟你的功能代码没有关闭..检查代码
-
打开控制台..检查错误
标签: javascript php codeigniter multidimensional-array