Welcome Guest, Not a member yet? Register   Sign In
Codeigniter and JQuery conflict?

I have a page written in php codeigniter with jquery. JSON seems to have a problem in locating the json function. Here's the scenario:

When you visit the site, you will be redirected to http://localhost/login. I have a test button in here to see if json is working well and here's the code:

    var item = $('input#txtUsername').val();
    $.post('login/testJSON', { 'item' : item },
      function(transport){ alert(transport.result); }, 'json');

CONTROLLER (under the login.php controller):
function testJSON(){
    $item = 'TESTJSON';
    $array = array('result' => $item);
    echo json_encode($array);

The above code works well if you are in the index of the login (http://localhost/login) however, if you have an invalid password you'll be redirected to http://localhost/login/authenticate which is the same page as the login index and if you try the test button for json, it will not work anymore.

Any ideas?

have you tried debugging with firebug?

Test it with absolute urls and as mentioned earlier, use firebug.

i'll try that and will post results later.

works well with absolute but not a good idea when u have to move the site to other domain.

i've tried adding '/' (/login/testJSON) and still doesn't work.

for absolute url use

^can i use this inside the javascript?

error console says:
"Error: base_url is not defined
Source File: http://localhost/projects/podz_en/js/authenticate.js
Line: 22"

yes you can
put this in the header before using any javascript
<scrpt type="text/javascript">
var base_url = '&lt;?php echo base_url(); ?&gt;';

and inside your javascript use the variable "base_url"

instead of scrpt I meant script but the forum is stripping it

^thanks! that solves the mystery! hehehe

Theme © iAndrew 2016 - Forum software by © MyBB