Passing jquery JSON from Codeigniter controller to view
I've been struggling  to make it work, but cannot pass the inserted data from the controler to the view in CI using JSON. The input value from the form is successfully inserted into the database, but cannot make it appear in the view.

This is my view file **ajax_view.php**: 

    <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery-1.4.2.min.js"></script>
    $(document).ready(function(){
						   
	$("#submit").click(function(){
							   
		var inp = $('#inp').val();
		
		
		$.post("ajax/ajax_input", { 'send' : inp },
		   function(data){
			 	alert(data.input_text);
				
		   }, "json");

	});
						   
    });
    </script>
       </head>
    <body>
    <form id="form1" method="post" action="">
     <label for="inp">Text</label>
     <input type="text" name="inp" id="inp" />
     <label for="submit"></label>
     <input type="submit" name="submit" id="submit" value="Submit" />
   </form>
     </body>

And this is the **ajax_input** method of the **ajax.php** controller:

    <?php
    // Initializing controller .....
    // .............................


     //ajax method
    function ajax_input(){
		$var_1 = trim($this->input->post('send'));
		$array = array('input_tekst' => $var_1);
		
		echo json_encode($array);
		$this->db->insert('ajax',$array);
    }

Trying to debug it with Firebug, it gives me that **data.input_text** is empty.

What am I doing wrong?

Passing jquery JSON from Codeigniter controller to view
===

I've been struggling  to make it work, but cannot pass the inserted data from the controler to the view in CI using JSON. The input value from the form is successfully inserted into the database, but cannot make it appear in the view.

This is my view file **ajax_view.php**: 

    <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery-1.4.2.min.js"></script>
    $(document).ready(function(){
						   
	$("#submit").click(function(){
							   
		var inp = $('#inp').val();
		
		
		$.post("ajax/ajax_input", { 'send' : inp },
		   function(data){
			 	alert(data.input_text);
				
		   }, "json");

	});
						   
    });
    </script>
       </head>
    <body>
    <form id="form1" method="post" action="">
     <label for="inp">Text</label>
     <input type="text" name="inp" id="inp" />
     <label for="submit"></label>
     <input type="submit" name="submit" id="submit" value="Submit" />
   </form>
     </body>

And this is the **ajax_input** method of the **ajax.php** controller:

    <?php
    // Initializing controller .....
    // .............................


     //ajax method
    function ajax_input(){
		$var_1 = trim($this->input->post('send'));
		$array = array('input_tekst' => $var_1);
		
		echo json_encode($array);
		$this->db->insert('ajax',$array);
    }

Trying to debug it with Firebug, it gives me that **data.input_text** is empty.

What am I doing wrong?
