I have a div:
<div id="contract"></div>
that gets populated by JQuery using innerHTML with strings from client side javascript and data (HTML) got from my server:
$('#submit').click(function () {
document.getElementById('contract').innerHTML = 'foobar';
var profile = $('#profile').val();
var query = {
'profile': profile
};
$.get('/foo/profileViewer', query, function (data) {
var result = $.parseJSON(data);
document.getElementById('contract').innerHTML += result ; //$('#contract').html(result); doesn't work either
})
});
I want to print just the contract
div
.
I tried the JQuery answers suggested here and here and all point to answers where div
already contains the text in HTML to start with and not something which is obtained from a server. Weirdly, if I remove the $.get
and implement one of the answers provided, "foobar"
does get printed. If I do not remove the $.get
, nothing gets printed. I tried using $.ajax
instead of $.get
but this does not resolve the issue. I tried using the CSS solution here but that messes up my data (HTML) coming from the server side as it already has CSS paged media embedded in it. Hence, I do not want to use the CSS solutions.
Could anyone please suggest me a good way to use JQuery to print a div
when the div
contains data obtained from the server side?