Welcome Guest, Not a member yet? Register   Sign In
passing data from js to controller

[eluser]Giorgio Nordo[/eluser]
I need to pass a data (just a numeric value) from a javascript function contained in a view to a controller.
I tryed to generate a cookie inside the javascript and to restore it inside the constructor of my controller by means of $this->input->cookie.
It seems that the value is not immediately available to the above CI method and in order to obtain the desired effect I have to manually refresh the page.
Obviously this is bad :-(

Some idea?

This forum is for CI add-ons libraries etc., next time please post in "Help, is this a bug?" forum.

Cookies are read by the browser only when page is being loaded, so if you send a cookie using JavaScript, you will be able to access it from CI on the next page load only.

If you need to call controller method from your view, without refreshing the page, you should use AJAX. Using jQuery this call would look something like this:

$.post("http://www.example.com/controller/method/", { my_data: "1" } );

[eluser]Giorgio Nordo[/eluser]
thank you and sorry for having used the wrong section (maybe a forum administrator chan move there this thread).

Theme © iAndrew 2016 - Forum software by © MyBB