Reputation: 119
I have this js code:
$.ajax({
type: 'POST',
url: url,
data: {id: id, 'YII_CSRF_TOKEN': token },
success: function(data) {
var content = $(data).find('.content');
console.log(content);
$('.content').html(content);
}
}).error(function() {
console.log('Error!');
})
Data in console.log():
[prevObject: jQuery.fn.jQuery.init[27], context: undefined, selector: ".content", constructor: function, init: function…]
My content do not get inserted. If I try:
$('.content').html('TEST');
It does work. I think it is the problem with jQuery objects.
Upvotes: 0
Views: 58
Reputation: 388416
.html() accepts a string as an argument, in your case content
is a jquery object, so you need to use .append() to append an element.
$('.content').empty().append(content);
Upvotes: 1