In a JS module in a Rails app I found this bit of code:
$body.on('ajax:success', '.js-comment-create', function(data, xhr, status) {
var content = $(xhr.content),
$comment = $(content.comment);
and I wonder why xhr.content
needs to be or should be wrappend in $()
?
I never paid attention to it as long as everything worked, but now, as I am debugging, I wonder why it is like this.
A quick test on the console shows that wrapping the xhr-Object return a JQuery object not a pure JS object. But what is the advantage of this in this particular situation where I just want to access data inside the object?
Edit: xhr.content
is a JSON object, where the key comment
holds a piece of html to replace some part of the DOM like so $(".aside ul.messages").prepend($comment);