0

I am making an ajax request from my codeigniter view in javascript function but nothing happens and the success alert (ok) pops up

function show_drop_downn(){
    document.getElementById("drop_downn").style.visibility = "visible"; 
    $.ajax({
        type: "POST",
        url: "http://localhost/ok/index.php/search/ajax_delete_ntify",
        success: alert('ok'),
    }); 
}

This is my controller it is working perfect, when i copy paste the url (used in ajax request) in my browser every thing goes good, controller makes a call to the model and it works perfect

function ajax_delete_ntify()
{
    echo "incontroller";
    $email=$this->session->userdata('email_of_user');
    $this->load->model('search_peoplee');
    $data['userid']= $this->search_peoplee->get_userid_from_email($email);
    foreach ($data['userid'] as $row)
    {
        $one=$row->userid;
    }
    $this->search_peoplee->delete_notifications($one);
    return;
}
5
  • 1
    What do you expect to happen? Also, check your consoles Network tab and verify the request is going thru. Commented Nov 8, 2013 at 16:05
  • actually i am implementing a notification method, when user hovers over a flag all the notifications are shown and are deleted Commented Nov 8, 2013 at 16:08
  • You need to pass success a function. In your case you are running alert('ok') and passing success the return value of alert (which is undefined). You need to do success: function(){ alert('ok'); } Commented Nov 8, 2013 at 16:08
  • What do you expect to happen after your AJAX call? Just running an AJAX call isn't going to display the contents of the URL on your page. You need to do that yourself. Commented Nov 8, 2013 at 16:10
  • ajax gives a call to controller and that controller gives a call to model which is programmed to delete a row from a table in database but that never happens, i have made it sure that my controller and model work perfectly Commented Nov 8, 2013 at 16:21

1 Answer 1

0

View :

function show_drop_downn(){
    document.getElementById("drop_downn").style.visibility = "visible"; 
    $.ajax({
        type: "POST",
        url: "http://localhost/ok/index.php/search/ajax_delete_ntify",
        success:function(
         console.log("success");
        )
    }); 
}

Controller :

function ajax_delete_ntify()
{
    echo "incontroller";
    $email=$this->session->userdata('email_of_user');
    $this->load->model('search_peoplee');
    $data= $this->search_peoplee->get_userid_from_email($email);
    $res=$this->search_peoplee->delete_notifications($data[0]->userid);
    if($res){
      echo json_encode(array('success'=>true));
    }else{
      echo json_encode(array('success'=>false));
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.