我有一个简单的ajax调用:
function init() {
$.ajax({
url: "./myFolder/user.php",
data: {
action: "init"
},
type: "post",
success: function (output) {
console.log("Success");
console.log("Output: " + output);
}
});
}
PHPinit
方法被调用,只需返回一些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数据在哪里?
在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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句