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.