【发布时间】:2021-09-15 10:46:09
【问题描述】:
这是我的 cart.php 文件。数组我编码为json并返回ajax函数:
$data = array();
$data['total'] = '10000';
$data['quantity'] = '10';
echo json_encode($data);
这是我的 index.php 文件。我创建函数 ajax 以在 cart.php 中返回我的数组值,但该值未定义:
function view()
{
$.ajax({
url: 'cart.php',
type:'POST',
data:{action:'total'},
datatype:'json',
success: function (data) {
alert(data.total);
}
});
}
【问题讨论】:
-
您显示的代码似乎不会产生您所描述的错误。正在发生其他事情,我们无法从这些信息中看到。
标签: javascript php arrays json ajax