我是否将值从 jquery 正确传递到我的控制器?
我正在使用 jquery 对表进行删除,
$('table#chkbox td a.delete').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var id = $(this).parent().attr('id');
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "<?php echo base_url().'index.php/libraryController/librarydelete' ?>",
data: { 'id': id },
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
我正确获取了 id 值,但我的数据参数没有传递到我的控制器,
function librarydelete($id)
{
$del = $id;
echo $del;
$this->librarymodel->deletebook_issue($id);
$this->session->set_flashdata('response','Deleted successfully');
redirect('libraryController/loadmagazinedetails');
}
任何建议...
我收到错误,
缺少 LibraryController 的参数 1 ::librarydelete() 和
未定义变量:id
I am doing a delete on a table using jquery,
$('table#chkbox td a.delete').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var id = $(this).parent().attr('id');
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "<?php echo base_url().'index.php/libraryController/librarydelete' ?>",
data: { 'id': id },
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
I am getting the id value correctly but my data parameter doesn't get passed to my controller,
function librarydelete($id)
{
$del = $id;
echo $del;
$this->librarymodel->deletebook_issue($id);
$this->session->set_flashdata('response','Deleted successfully');
redirect('libraryController/loadmagazinedetails');
}
Any suggestion...
I am getting the error,
Missing argument 1 for libraryController::librarydelete()
and Undefined variable: id
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您正在发布数据,因此您可以像这样获取 id:
看起来您正在使用 codeigniter,所以这会更好:
Your are posting the data, so you can get the id like this:
Looks like you are using codeigniter, so this would be even better:
将控制器功能参数中的 id 更改为 $id
意味着,你的函数应该是
Change id to $id in controller function parameter
means, your function should be
也许是因为您使用了变量名称“data”两次。尝试将 var data 重命名为 var mydata。
Perhaps it is because you are using the variable name 'data' twice. Try renaming var data to var mydata.
您传递数据的方式是错误的。这就是您应该设置数据的方式。
var data= {id: id };
在你的情况下,让我不要在后期操作中使用变量并向你展示它是如何完成的。
编辑:修改代码以正确方式传递数据后。
嘿,我没有遵循 php 中的 MVC 框架。但由于您正在对操作进行发布,因此您始终可以通过以下方式获取数据:
然后您可以使用此 id。
另外,如果您仍然想使用该功能:
只需将uri操作修改为existingurl+/即,将id附加到末尾和您的路由映射中(如果在.nets实现中的php中存在类似的东西,则有1)只需添加路线。
The way you are passing data is wrong. This is the way you should be setting data.
var data= {id: id };
in your case let me not use the variable in the post action and show you how its done.
Edit: After you modified your code to pass data the right way.
Hey I have not followed MVC framwework in php. but since you are doing a post on the action you can always get the data the following way:
and then you can use this id.
Also if you still want to use the function:
just modify the uri action to existingurl+/ i.e append the id to the end and in your route map (if there exists something like this in php in .nets implementation there is 1) just add that route.