The jquery load method loads HTML from a remote file and injects it into the DOM. For example, to load the feeds.html file into the div with the ID of feeds, you would do this:
$("#feeds").load("feeds.html");
Is this an alternative to calling a partial with the Rails replace_html method or is the functionality slightly different?
page.replace_html 'feeds', :partial => 'main/feeds',
:locals => {:feed => @feed_data }
[EDIT]: As Craig Stuntz points out, replace_html returns Javascript instead of HTML - what's the advantage/disadvantage of this? Does it just mean that the fragment you return has more functional capabilities in the same way that a web page that uses Javascript is more powerful than a regular HTML page? Or is there some other reason for returning Javascript instead of HTML?
The end result is much the same, but they work in a very different way. The load method means that your server returns an HTML fragment, and jQuery inserts it into the page. The replace_html method means that your server is returning JavaScript instead of HTML, and this JavaScript is executed to insert an HTML fragment into the page. So the final resulting HTML is the same, but the traffic between the client and the server is very different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With