我是ajax的新手,我不知道我在做什么是正确的:
这是我的PHP控制器:
public function checkAllApprove(){
$userX = $this->session->userdata('userID');
$result = $this->lawmodel->startBattle($userX);
foreach($result as $row){
$data['getData'] = $this->lawmodel->getID($row->challengerID);
if($row->challengerApprove == "0"){
echo "Wait for your challenger to approve battle!";
}
else if($row->challengerApprove == "1"){
$data['content'] = 'sampleBattle';
$this->load->view('include/template2', $data);
}
}
}
这是我的Ajax电话:
<script type="text/javascript">
var auto_refresh = setTimeout(
function ()
{
$('#acceptedBattle').load('<?php echo "http://127.0.0.1/ProgVsProg/main/checkAllApprove"?>').fadeIn("slow");
},5000); // refresh every 10000 milliseconds
</script>
Ajax调用不会显示在我的控制器函数内部。我需要显示控制器的数据。我不知道这是否是使用ajax函数的正确方法,还是使用带有setTimeout()
的ajax调用我的控制器的另一种方式?
答案 0 :(得分:0)
查看您的PHP函数:
public function checkAllApprove(){
$userX = $this->session->userdata('userID');
$result = $this->lawmodel->startBattle($userX);
foreach($result as $row){
$data['getData'] = $this->lawmodel->getID($row->challengerID);
if($row->challengerApprove == "0"){
echo "Wait for your challenger to approve battle!";
}
else if($row->challengerApprove == "1"){
$data['content'] = 'sampleBattle';
$this->load->view('include/template2', $data);
}
}
}
没有return
。所以没有任何东西出来的功能。除了echo "Wait for your challenger to approve battle!";
不清楚你的大框架是如何工作的,但也许这一行:
$this->load->view('include/template2', $data);
应该使用return
:
return $this->load->view('include/template2', $data);
或许基于其他echo
行为的echo
?
echo $this->load->view('include/template2', $data);