未使用Javascript post方法将json数组发布到PHP
他认为:未使用Javascript post方法将json数组发布到PHP,javascript,php,jquery,json,Javascript,Php,Jquery,Json,他认为: function updateData(that){ f = new test(); for (var i = 0; i < dataContext.length; i++) { f.test.push(new Person(dataContext[i].test, dataContext[i].test1, dataContext[i].Line1, dataContext[i].Id)); } $.post("<?php ech
function updateData(that){
f = new test();
for (var i = 0; i < dataContext.length; i++)
{
f.test.push(new Person(dataContext[i].test, dataContext[i].test1, dataContext[i].Line1, dataContext[i].Id));
}
$.post("<?php echo $base_url;?>index.php/controller/function/<?php echo $details['Id'];?>", { data: JSON.stringify(f) }, function (res) {
});
}
返回一个空数组
数据基本上在javascript向导中。似乎当我点击“完成”时,页面不会自动刷新$_仅当页面首次加载时才调用POST
我对javascript非常陌生,不知道我做错了什么,干杯。尝试JSON.stringify(那)
代替JSON.stringify(f)
像
function updateData(that){
var url="<?php echo $base_url;?>index.php/controller/function/<?php echo $details['Id'];?>";
$.post(url, { data: JSON.stringify(that) },function (res) {
alert(res);
});
}
function updateData($id=''){
print_r($_POST);
}
给你的php函数起一个名字
,或者像这样调用表单jquery
// call updateData function in your controller
var url="<?php echo $base_url;?>index.php/controller/updateData/<?php echo $details['Id'];?>";
f
从未定义过。请修改它,请参见上面的“f”是我要传递到JSON对象中的数组
// call updateData function in your controller
var url="<?php echo $base_url;?>index.php/controller/updateData/<?php echo $details['Id'];?>";
function updateData($id=''){
print_r($_POST);
}