javascript 如何通过javascript函数调用codeigniter函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18479760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call codeigniter function through javascript function
提问by user2422387
This is not working in my codeigniter function i have the id and cannot get that id.Please help me. this is my view and i am trying to send my id through the function.
这在我的 codeigniter 函数中不起作用,我有 ID,但无法获取该 ID。请帮助我。这是我的观点,我正在尝试通过该功能发送我的 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>
回答by Code Prank
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;
回答by Dev
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
}
回答by Nilesh patel
<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
}