[英]How to call codeigniter function through javascript function
This is not working in my codeigniter function i have the id and cannot get that id.Please help me. 这在我的codeigniter函数中不起作用,我有ID并且无法获取该ID。请帮助我。 this is my view and i am trying to send my id through the function.
这是我的观点,我正在尝试通过该函数发送我的ID。
<script type="text/javascript">
function makeajaxcall(id) {
//alert(id);
var r = confirm("Do you want to Delete");
if (r == true) {
window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user?id='.id);?>";
} else {
x = "You pressed Cancel!";
alert(x);
}
}
</script>
Change this line: 更改此行:
window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user?id='.id);?>";
To: 至:
window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user');?>?id="+id;
Try using this 试试这个
window.location.href = "<?php echo site_url('controller_d/login/admin_link_delete_user/'.id);?>";
assuming that in your controller you have this method 假设在您的控制器中您具有此方法
function admin_link_delete_user($id){
echo $id;// u'll get the id which you are passing through javascript
}
<script type="text/javascript">
function makeajaxcall(id)
{
//alert(id);
var r=confirm("Do you want to Delete");
if (r==true)
{
$.post("<?php echo site_url('controller_d/login/admin_link_delete_user/');?>", {id:id},
function(data) {
alert(data+"a");
}, 'json');
}
else
{
x="You pressed Cancel!";
alert(x);
}
}
</script>
in controller 在控制器中
function admin_link_delete_user(){
echo $this->input->post('id');
//perform your code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.