I have been working on a Rails application where I implemented an AJAX / JSON controller to facilitate dynamic HTML updates within the view. For guidance, I referred to this helpful resource:
When making a call like this:
../related.json?vendor_id=1&budget_id=1
, the raw HTML partial required for updating (consisting of multiple table rows) is returned.
The call in question looks something like this:
Rails.ajax({
url: url,
type: 'GET',
success: function(data) {
document.getElementById("related").innerHTML = "data"
// alert(data)
}
})
Upon manually inspecting the JSON request in the browser, the expected HTML output is observed. However, when attempting to replace the HTML content or even displaying the data in a test alert, the response received is [object HTMLDocument]
. Following the guide I referenced, using data.html
to populate the innerHTML did not yield the desired result. This issue could potentially be related to UJS / JQuery functionalities.
How can I successfully update that DOM element with the raw text obtained from the JSON call?