In a non-AJAX web app, the URL would contain my view parameters (e.g. mysite?page=2&sort=name). In an AJAX app, where do I store the same info? In the Session object?
In a non-AJAX web app, the URL would contain my view parameters (e.g. mysite?page=2&sort=name).
Share
I’m assuming you want to know how to pass additional params with an AJAX call. This really depends on how you’re formulating the AJAX call.
If you’re using the built-in Rails helpers, you can pass additional params inside the
url_forhelper. For example, lets say that you have aproductsroute and you want to AJAX load a list of all products. Thelink_tohelper might look something like this (Rails 3.2)If on the other hand you’re using a JavaScript framework like jQuery, you can pass additional params using the
dataoption. For exampleStoring this data (page, sort, etc.) can be done multiple ways also. The easiest way would be to store this data inside a JavaScript variable.
Another solution is to store this information in the
dataattribute of a particular DOM element on the page. For example, if you have a<div id='products'>that contains a list of the paginated, sorted products, you could store the information like this (jQuery)