我想通过ajax请求连接Index控制器,想要返回data数据,但是数据信息是在引入的一个类文件里生成的,怎么返回这个数据呢
这是控制器文件
<?php
namespace app\index\controller;
use think\Controller;
use a\B;//引入B类
class Index
{
public function index()
{
$fetion = new B();
$content = $_POST['content'];
$res=$fetion->C( $content);
}
}这是类文件<?php
namespace a;
class B{
public function C($content){
$message="";
if($content =='1'){
$message="是1";
}else{
$message="不是1";
}
//我想返回这个 $message
$data['msg'] = $message;
$this->ajaxReturn($data);
//返回的是空值
}
}这是请求的api.ajax({
url : OpenAPI.Index,
method : 'post',
timeout : 30,
dataType : 'json',
returnAll : false,
data : {
values : {
content : "测试一下API接口"
}
}
}, function(ret, err) {
alert(JSON.stringify(ret))
}),怎么才能返回那个$message信息呢,在请求端输出 出来。对编程一窍不通,高手请帮忙,先谢谢啦
最佳答案