Welcome Guest, Not a member yet? Register   Sign In
passing data using jquery(json) instead of ajax
#1

[eluser]echo sara[/eluser]
Hi,

Does anyone know how to use jquery with the json function using codeigniter? Not sure how this would work. Can someone show me a example or recommend me to a tutorial on the net.

Thanks soo much!!!
#2

[eluser]jblack199[/eluser]
Code:
$(document).ready(function() {
   $('#submit_button').click (function () {
    var item = $('#item').val();
        $.post("/demo/processs", { 'item' : item },
        function (data) {
            alert(data.result);
        }, "json");
   });
});
then in controller demo.php you would need a function 'process'
Code:
function process() {
    $item = trim($this->input->post('item'));
    $array = array('result' => $item);
    echo json_encode($array);
}


note: just wrote this up, havent tested the code.. beware!
#3

[eluser]echo sara[/eluser]
Thanks for the example, very useful. I'm a little confused tho; how come in the controller (demo.php) you did not load view (this->load->view('viewpage', $array). Is that a necessary in this case?
#4

[eluser]danmontgomery[/eluser]
It's an option, but not necessary.. you would just want to throw the json_encode() part into the view.




Theme © iAndrew 2016 - Forum software by © MyBB