我想向 Posts 控制器发送一些数据(图像、文本、...):
$('#home').click(function (){
var xhr = new XMLHttpRequest();
xhr.open("POST","/Portfilo/posts/test",true);
xhr.send("id=10");
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
alert(xhr.responseText);
}
}
});
测试动作是:
public function test()
{
$this->layout = 'ajax';
//$id = $this->params['named']['id'];
if($this->request->named){
echo "Yesssssss";
}
else {
echo 'Oh No';
}
}
我如何从这个连接(xmlhttprequest)中检索这些数据。
我读了这篇 文章,但是像这样的函数或属性:
// Passed arguments
$this->request->pass;
$this->request['pass'];
$this->request->params['pass'];
或者
// named parameters
$this->request->named;
返回给我“哦 Noooo”消息。
如何从这个请求中检索这些参数和数据?