我有一个简单的ajax调用:
function init() {
$.ajax({
url: "./myFolder/user.php",
data: {
action: "init"
},
type: "post",
success: function (output) {
console.log("Success");
console.log("Output: " + output);
}
});
}
调用PHP init
方法,只需返回一些json数据:
function init() {
$arr = array(
array(
"region" => "valore",
"price" => "valore2"
),
array(
"region" => "valore",
"price" => "valore2"
),
array(
"region" => "valore",
"price" => "valore2"
)
);
return json_encode($arr);
}
但我的控制台说:
Success
Output:
因此输出变量为空。我的json数据在哪里?
答案 0 :(得分:1)
在user.php
页面上您需要执行以下操作: -
function init() {
$arr = array(
array(
"region" => "valore",
"price" => "valore2"
),
array(
"region" => "valore",
"price" => "valore2"
),
array(
"region" => "valore",
"price" => "valore2"
)
);
echo json_encode($arr);
}
答案 1 :(得分:-2)
你应该在你的user.php中有这样的东西:
die(init());