Php Codeigniter Rest和Ajax没有得到期望的结果
我的codeigniter控制器设置如下:Php Codeigniter Rest和Ajax没有得到期望的结果,php,ajax,codeigniter,rest,Php,Ajax,Codeigniter,Rest,我的codeigniter控制器设置如下: <?php include('./application/libraries/REST_Controller.php'); class Restful extends REST_Controller{ public function user_get() { //URL as such: // http://localhost/rest/restful/user/id/1 //notice array('retur
<?php
include('./application/libraries/REST_Controller.php');
class Restful extends REST_Controller{
public function user_get()
{
//URL as such:
// http://localhost/rest/restful/user/id/1
//notice array('returned'$this->get(id)) ->>>> get the id thats being sent
$data = array('returned: '.$this->get('id'));
$this->response($data);
//returns :
// xml <item> returned: 1</item> /xml
}
}
我认为您需要将函数名定义为“user”,而不是“user\u get”。所以控制器代码将是
public function user()
{
$data = array('returned: '.$this->get('id'));
$this->response($data);
}
}
它必须是user_get->,如果我直接运行控制器并传递它工作的值。但是当我从ajax调用它时,它只会给我[Object Document]:有一个关于codeigniter rest@nettuts的完整教程,我在这里遵循了它:你的路由.php
看起来像什么?你试过url:'http://localhost/restful/user_get/?id=1“,
?
public function user()
{
$data = array('returned: '.$this->get('id'));
$this->response($data);
}
}