jQuery ajax success not work in codeigniter

Posted by softboxkid on Stack Overflow See other posts from Stack Overflow or by softboxkid
Published on 2012-06-22T02:39:04Z Indexed on 2012/06/22 3:16 UTC
Read the original article Hit count: 382

Filed under:
|
|

I had a problem with ajax. The trick is, when user click on the top hyperlink, it will send the link id through onclick=getChildMenuLink(str). Then from getChildMenuLink(str) function, it will send the str to the controller (to set the session) thru ajax. here is the code.

html code

<a href="http://localhost/ejournal/index.php/sysconfig" onclick="getChildMenuLink(1)">Administrator</a>

<a href="http://localhost/ejournal/index.php/welcome" onclick="getChildMenuLink(22)">Home</a>

jquery ajax

function getChildMenuLink(str) {
        'use strict';


        $.ajax({
            type: 'POST',
            url: "http://localhost/ejournal/index.php/sysconfig/getLink/" + str,
            success: function () {} // End of success function of ajax form           
        });  // End of ajax call

        //alert(document.URL);    
    }

codeigniter controller

function getLink($id='')
{
    $this->session->unset_userdata('parentLink'); 
    $this->session->set_userdata('parentLink',$id);
}

if i uncomment the alert() function on that script, it work. the PHP session is properly set. please help me

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX