它是我的控制器。它只是我的功能更新和删除
function update($id=null){
if(!isset($_POST))
show_404();
if($this->m_user->update($id))
echo json_encode(array('success'=>true));
else
echo json_encode(array('msg'=>'Failed Update'));
}
function delete(){
if(!isset($_POST))
show_404();
$id = intval(addslashes($_POST['id']));
if($this->m_user->hapus($id))
echo json_encode(array('success'=>true));
else
echo json_encode(array('msg'=>'Failed Delete'));
}
在我的模型中更新和删除它的功能
function update($id){
$this->db->where('id',$id);
return $this->db->update('user',array(
'name'=>$this->input->post('name',true),
'address'=>$this->input->post('address',true),
'dob' => date('Y-m-d', strtotime(str_replace('-', '/', $this->input->post('dob')))),
'email'=>$this->input->post('email',true),
'username'=>$this->input->post('username',true),
'password'=>$this->input->post('password',true),
'level'=>$this->input->post('level',true)));
}
function delete($id){
$this->db->where('id', $id);
return $this->db->delete('user', array('id' => $id));
}
public function getJson()
{
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'id';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';
$offset = ($page-1) * $rows;
$result = array();
$result['total'] = $this->db->get('user')->num_rows();
$row = array();
$this->db->limit($rows,$offset);
$this->db->order_by($sort,$order);
$criteria = $this->db->get('user');
foreach($criteria->result_array() as $data)
{
$row[] = array(
'name'=>$data['name'],
'address'=>$data['address'],
'dob'=>$data['dob'],
'email'=>$data['email'],
'username'=>$data['username'],
'password'=>$data['password'],
'level'=>$data['level'],
);
}
$result=array_merge($result,array('rows'=>$row));
return json_encode($result);
}
}
我的观点中的javascript
<script type="text/javascript">
var url;
function newUser(){
$('#dlg').dialog('open').dialog('setTitle','New User');
$('#fm').form('clear');
url = '<?php echo site_url('admin/tambahuser'); ?>';
}
function editUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$('#dlg').dialog('open').dialog('setTitle','Edit User');
$('#fm').form('load', row);
url = '<?php echo site_url('admin/ubah'); ?>/'+row.id;
}
}
function saveUser(){
$('#fm').form('submit',{
url: url,
onSubmit: function(){
return $(this).form('validate');
},
success: function(result){
var result = eval('('+result+')');
if (result.errorMsg){
$.messager.show({
title: 'Error',
msg: result.errorMsg
});
} else {
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
}
function destroyUser(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('Confirm','Are you sure you want to Delete this user?',function(r){
if (r){
$.post('<?php echo site_url('admin/hapus'); ?>',{id:row.id},function(result){
if (result.success){
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.errorMsg
});
}
},'json');
}
});
}
}
</script>
答案 0 :(得分:0)
“text / javascript”中的 var url 正在寻找位于此页面的同一文件夹或子文件夹中的现有php扩展文件。所以你应该在“url = ...”之后放置应该是同一个文件夹中的现有php文件。