本文介绍了AJAX调用PHP文件:返回值为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的ajax调用:
I have a simple ajax call:
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数据:
The PHP init method gets called and simply should return some json data:
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数据在哪里?
So the output variable is empty. Where is my json data?
推荐答案在 user.php 页面上你需要这样做: -
On user.php page you need to do :-
function init() { $arr = array( array( "region" => "valore", "price" => "valore2" ), array( "region" => "valore", "price" => "valore2" ), array( "region" => "valore", "price" => "valore2" ) ); echo json_encode($arr); }更多推荐
AJAX调用PHP文件:返回值为空
发布评论