When I try to append() the XHTML result of a $.get() to a container element,
$.get("my-webservice", function(data){
$("#some-container").append(data);
});
I get an error:
TypeError: 'null' is not an object (evaluating 'e.ownerDocument')
I also tried:
$("#some-container").append($(data));
and get the same error. load() works fine, so I know the webservice is returning good data:
$("#some-container").load("my-webservice");
At the webservice end, if I encode the XHTML as a string before returning to $.get(), everything works as expected. The append() docs say it accepts a string, DOM Element, or jQuery object - I suspect I am getting something about that wrong. Any suggestions?
The webservice is just returning some simple bootstrap XHTML:
<div class="row">
<div class="span5">Div stuff</div>
<div class="span4">More div stuff</div>
</div>
jQuery is trying to make its best guess as to the type of document being returned when you use the $.get function without specifying a dataType. As the last parameter of the $.get function try adding 'html' to specify the dataType. See the jQuery documentation for more information.
$.get("my-webservice", function(data){
$("#some-container").append(data);
}, 'html');
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