我有一个jquery,当单击复选框时会被调用。jquery执行,但是PHP文件没有被调用(至少我认为它没有被调用)。
我不能将" echo“语句放在PHP函数中,因为PHP没有返回任何内容(它只是在jquery调用时更新一个表)+我也不知道它会在哪里回显!
jquery:
$('#notify_checkbox').click(function(){
if($('#notify_checkbox').is(':checked'))
{
$.post("/upic/update_notify", { checked: "y", email: "<?php echo $this->session->userdata('email');?>" });
$( "#notifyresult" ).html( "<p>Awesome, we'll send you an email!</p>" );
}
else
{
$.post("/upic/update_notify", { checked: "n", email: "<?php echo $this->session->userdata('email');?>" });
$( "#notifyresult" ).html( "<p>Okay, we won't email you.</p>" );
}
});
和PHP (我使用的是CodeIgniter框架):
function update_notify()
{
// Passed through AJAX
$notify = $_POST['checked'];
$email = $_POST['email'];
$this->load->model('musers');
$query = $this->musers->update_user_notify($email, $notify);
}
编辑:使用$.post工作中的完整URL ($.post)。但是,只调用控制器和函数就没有了。
发布于 2011-05-20 00:53:58
在使用log_message进行调试时,我发现使用CodeIgniter很有用,下面看一看:http://codeigniter.com/user_guide/general/errors.html
除此之外,你为什么认为这个行动是不被召唤的呢?
发布于 2012-08-20 08:43:28
你最好用:
$.post('<?=site_url('controller/function');?>',{data here})
https://stackoverflow.com/questions/6066409
复制相似问题