[英]Ajax request no response using codeigniter
有人可以用這個簡單的代碼幫助我嗎,我有一個按鈕,當用戶提交該按鈕時,它將加載一個將調用ajax請求以僅更新表中一個字段的javascript,因此我將一個對此方法執行的contoller傳遞給了我的ajax請求但什么都沒發生。這是我的看法
<!--body part--->
echo "<button class='btn btn-info dropdown-toggle notify-btn' data-toggle='dropdown' 'href='#' value=".$count." onclick='notify(".$count.")'>".$count."</button>";
<!--Here is my javascript--->
function notify(count){
$.ajax({
type: 'POST',
url:<?php echo base_url("notifications/set")?>,
success:function(response){
alert("Success");
}
});
}
<!--Here is my Controller--->
class Notifications extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('notification_model');
}
public function index(){
$this->set();
}
public function set(){
$this->notification_model->set_notifications();
}
<!--Here is my Model--->
<?php class Notification_model extends CI_Model {
function set_notifications(){
$this->db->where('notification_status','active');
$this->db->set('notification_status',"inactive",FALSE);
$this->db->update('messages');
}
}
?>
只是快速瀏覽一下,您的AJAX請求很可能失敗,因為您的URL沒有用單引號引起來。 請嘗試以下操作(注意URL周圍的單引號):
function notify(count){
$.ajax({
type: 'POST',
url: '<?php echo base_url("notifications/set"); ?>',
success:function(response){
alert("Success");
}
});
}
希望能幫助到你...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.