CodeIgniter Forums
returning value from jquery to controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: returning value from jquery to controller (/showthread.php?tid=43272)



returning value from jquery to controller - El Forum - 07-06-2011

[eluser]mehwish[/eluser]
hi,Can anyone tell me how to return a variable from a jquery function in view to controller?
for example this is what i have written in my view file :

Code:
[removed]

var i=0;

$("button").click(function () {
         myFunction();
         alert(i);
         [b]return i;[/b]             [i]how to return this i variable to controller[/i]  
    });

function myFunction()
{    
    i++;
    $("button").after('<input type="text" name="n"/>',i);
}
[removed]


Actually i know how to pass values using anchor() to controller but it seems different i have tried. Please help me out in passign this i's value from script to controller.

Thank you


returning value from jquery to controller - El Forum - 07-06-2011

[eluser]toopay[/eluser]
search on 'AJAX' keyword.


returning value from jquery to controller - El Forum - 08-03-2011

[eluser]nuwanda[/eluser]
Use jQuery's load function to call your controller method.

Echo the data from the controller function and it will be returned to your view.