jQuery and CodeIgniter AJAX with JSON not working
        Posted  
        
            by thedp
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by thedp
        
        
        
        Published on 2010-03-27T23:08:35Z
        Indexed on 
            2010/03/27
            23:13 UTC
        
        
        Read the original article
        Hit count: 397
        
Hello,
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter. But for some weird reason it's not working.
The jQuery code:
var item = "COOL!";
$.post("http://192.168.8.138/index.php/main/test", { "item" : item },
         function(data){
            alert(data.result);
         }, "json");
The CodeIgniter code:
<?php
class main extends Controller {
   function test() {
      $item = trim($this->input->post('item'));
      $array = array('result' => $item);
      echo json_encode($array);
   }
}
?>
I tried to access the http://192.168.8.138/index.php/main/test page manually and it seems to be working, I got: {"result":""}
I also tried to use Firebug to see XMLHttpRequest but saw nothing.
I have no idea what am I doing wrong... Need help really badly. Thank you.
© Stack Overflow or respective owner