我正在使用 Dojo Datagrid小部件开发网站,使用 Restful service
填充数据我使用的宁静图书馆来自chriskacerguis Codeigniter:
https://github.com/chriskacerguis/codeigniter-restserver
我使用的唯一框架是 Dojo Toolkit 1.10
我已经使用GET请求填充Datagrid而没有问题,但是当我尝试修改datagrid的一条记录并且datagrid触发PUT请求时,问题出现了。
我从控制台获得以下内容:
XHR完成加载:获取“www.website/Codeigniter/Civilweb/restful/user/?id=*”。的dojo.js:15
PUT www.website/Codeigniter/Civilweb/restful/user/1 404(未找到) dojo.js:15
XHR完成加载: PUT “www.website/Codeigniter/Civilweb/restful/user/1”。的dojo.js:15
_5a6:无法加载www.website/Codeigniter/Civilweb/restful/user/1 status:404 {message:“无法加载www.website/Codeigniter/Civilweb/restful/user/1 status:404 “,响应:对象,状态:404,responseText:”“,xhr:XMLHttpRequest ...} dojo.js:15
我不知道为什么但最后在我的“MySQL”数据库上修改了记录,但我需要刷新页面以查看更改。
这是我的观点代码:
var dataStoreSetup1 = new dojox.data.JsonRestStore({
target:"http://localhost/Codeigniter/Civilweb/restful/user/" ,
idAttribute: 'id',
idProperty: 'id'
});
var layoutSetup1 = [{
defaultCell: { width: 8, editable: true, type: cells._Widget, styles: 'text-align: center;' },
cells: [
{name: 'Name', field: 'name' ,width:10},
{name: 'Position', field: 'position' ,width:8},
{name: 'User', field: 'user' ,width:8},
{name: 'Password', field: 'password' ,width:8},
{name: 'Role', field: 'role' ,width:6}
]
}];
var gridSetup1 = new DataGrid({
id: 'gridSetup1',
query: { id: "*" },
store: dataStoreSetup1,//dojo.data.ObjectStore({objectStore: dataStoreSetup1}),
structure: layoutSetup1,
loadingMessage: "Loading data...",
noDataMessage : "No results found.",
clientSort: 'false',
selectionMode:'single',
rowSelector: '0px',
onApplyCellEdit : procOnApplyCellEdit
});
//append the new grid to the div
gridSetup1.placeAt("gridDivSetup1");
//Call startup() to render the grid
gridSetup1.update();
gridSetup1.startup();
function procOnApplyCellEdit() {
dataStoreSetup1.save();
}
这是我的控制者:
function user_get() //respond with information
{
$this->load->model('setup_model');
if(!$this->get('id'))
{
$this->response(NULL, 400); //Bad Request
}
$user = $this->setup_model->get_users_data();
if($user)
{
$this->response->format = 'json';
$this->response($user, 200); //200 being the HTTP response code
}
else
{
$this->response(NULL, 404); //Not found
}
}
function user_put() // update an existing user and respond with a status/errors
{
$this->load->model('setup_model');
$result = $this->setup_model->put_users_data($this->put('id'),$this->put('name'),$this->put('position'),$this->put('user'),$this->put('password'),$this->put('role'));
if($result)
{
$this->response($result, 200); //200 being the HTTP response code
}
else
{
$this->response(NULL, 404); //Not found
}
最后这是我的模特:
public function get_users_data()
{
$query = $this->db->get('users');
if($query->num_rows() > 0)
{
return $query->result_array();
}
}
public function put_users_data($id,$name,$position,$user,$password,$role)
{
$data = array(
'name' => $name,
'position' => $position,
'user' => $user,
'password' => $password,
'role' => $role
);
$this->db->where('id',$id);
$this->db->update('users',$data);
}
我做错了什么以及为什么我从PUT方法得到这个404错误?
提前致谢
答案 0 :(得分:0)
dojo put请求似乎很好。您应该检查控制器的函数user_put()中$ result的结果。它是异步的吗?