I'm使用的Dojo DataGrid小部件在開發一個網站,有RESTful服務道場的DataGrid笨休息和PUT方法
的寧靜庫I'm使用填充數據是從chriskacerguis上笨:
https://github.com/chriskacerguis/codeigniter-restserver
是I'm使用唯一的框架是Dojo Toolkit的1.10
從來就得到了填充DataGrid不使用GET請求的問題,但是,當我正嘗試修改DataGrid的一個記錄和數據網格觸發一個PUT請求問題就來了。
我從控制檯執行以下操作:
XHR加載完成:GET 「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狀態:404 {消息:「無法加載www.website/Codeigniter/Civilweb/restful/user/ 1狀態: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);
}
做什麼I'm錯誤和爲什麼我從PUT方法得到這個404錯誤?
在此先感謝
道場放置請求似乎很好。你可能應該檢查你的控制器的函數user_put()中$ result的結果。它是異步嗎? http://www.restapitutorial.com/lessons/httpmethods。html – Bobz79 2014-10-20 03:12:26
感謝Bobz79問題是在$結果,我不知道爲什麼,但$結果返回NULL。現在它像一個魅力。再次感謝 – 2014-10-20 19:40:13
酷,很高興知道它現在的作品。我將發佈評論作爲答案以獲得積分:-) – Bobz79 2014-10-25 01:45:55