如何从ajax和php获取返回值

如何从ajax和php获取返回值,ajax,Ajax,我设置了一个php文件,名为ajax,与我的数据库交互。到目前为止,我已经成功地使用json从sql请求中获取数据。现在,我从php文件返回自己的值,并尝试将该值返回到javascript中。但他们回来时却空无一人。我就是这样做的: // in the php file, gets data and database, and returns a number through echo $result = 2; echo $return; //the javascript which call

我设置了一个php文件,名为ajax,与我的数据库交互。到目前为止,我已经成功地使用json从sql请求中获取数据。现在,我从php文件返回自己的值,并尝试将该值返回到javascript中。但他们回来时却空无一人。我就是这样做的:

// in the php file, gets data and database, and returns a number through echo
$result = 2;
echo $return;

//the javascript which calls the ajax and gets the value
var temp = ajaxdb(args);
showError(temp);
show error在div中显示变量

我知道我的函数工作正常,因为当我返回json字符串并将其解析为数组时,它们工作正常。但是如何从php获取自定义值呢?

echo json\u encode($return)