igor-alexandrov / wiselinks

If Turbolinks are not enough for you. Wiselinks makes your application work faster.
MIT License
723 stars 89 forks source link

Request and return js response #46

Open thehappycoder opened 11 years ago

thehappycoder commented 11 years ago

I have the same problem as this person http://stackoverflow.com/questions/19213399/is-it-possible-to-send-javascript-request-using-wiselinks

Can it be a feature request?

igor-alexandrov commented 11 years ago

Can you please provide a real example of how this can be used? And we will try to find solution. Thanks.

thehappycoder commented 11 years ago

We are developing a web application that has categories (can be nested) and there are items in each category. When category is clicked and response is successful, we need to update the main content -- a list of items in selected category and also update the menu of categories in order to show subcategories of selected category and unselect previously selected category.

Later there will be similar cases. The web app basically consists of several sections and after every request there will be need to update elements on 1 or more sections.

igor-alexandrov commented 11 years ago

As I said on StackOverflow the best appoach here will be to use page:done JS event, or add custom click event to this links and send additional AJAX request to load tree, or maybe add some JS call to HTML that you are loading from server.

Wiselinks is designed to provide emulation of native link following without reload any unneeded assets and parts of HTML code, so I think that data type should be HTML.

Will proposed solutions work in your situation?

thehappycoder commented 11 years ago

These solutions may work but I think I am going to use history.js directly then.

Additional requests -- not clean page:done -- I prefer to keep this logic in different rails views. It's quite hackish anyway :)

igor-alexandrov commented 11 years ago

If you want to keep logic in different rails views, then in view, that you a loading from server you can use something like:

javascript:
  $(document).ready(function() {
    new Views.Favorites.Index($('@container))
  });

And this code will fire when view is loaded.