Ajax 如何使用&x201C;响应”;来自CakePHP(2.5)中的任何XMLHTTPREQUEST

Ajax 如何使用&x201C;响应”;来自CakePHP(2.5)中的任何XMLHTTPREQUEST,ajax,json,xmlhttprequest,cakephp-2.0,Ajax,Json,Xmlhttprequest,Cakephp 2.0,我在控制器的帖子里看到了动作“pega”: public function pega($id = null) { $posts = $this->Post->findById($id); foreach($posts as $pok) { $foda = $pok['love']; } $this->set('foda', $foda); $this->s

我在控制器的帖子里看到了动作“pega”:

public function pega($id = null)
{                       
    $posts = $this->Post->findById($id);
    foreach($posts as $pok)
    {
        $foda = $pok['love'];
    }   

    $this->set('foda', $foda);
    $this->set('_serialize', array('foda'));
}
在我的布局中,我尝试执行一个请求来捕获函数“pega”中的数据,并将其放入标记html中:

<script>
var xmlhttp = new XMLHttpRequest();
var url = "http://localhost:81/booklandia/posts/pega/<?php echo $post['Post']['id'];?  >.json";

xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 

var out = JSON.parse(xmlhttp.responseText);
 function loap (){ 
 var arr = out[0];
document.getElementById("id01").innerHTML = arr;
}

}

}
xmlhttp.open("GET", url, true);
xmlhttp.send();

var xmlhttp=new XMLHttpRequest();
变量url=”http://localhost:81/booklandia/posts/pega/