I am reading the Rails guides, in particular I am reading this: http://guides.rubyonrails.org/working_with_javascript_in_rails.html#server-side-concerns The part that is a little bit confusing to me is the response. It says that if the create action receives an AJAX request then it will return the javascript code that will insert the user in the page. I have found other solutions in which the client receives a json object (instead of javascript code) and builds the corresponding DOM elements and inserts them in the page. My questions are:
- Is it a better to receive json objects and build DOM elements and insert them on the page than receive javascript code and execute it so that new content gets added to the page? What are the best practices about it?
- In this example, what will the ajax call receive? javascript code, a json object or both?