I am using jquery ajax request which gets the HTML content from backend code. If status is OK, I am appending HTML content to a div. I am using following code to append div using jquery ajax. as $('#divElm').html(response.data);
. But after appending I am getting following error:
SyntaxError: missing } in compound statement
The HTML content rendering from backend (ie., response.data) contains the following which is causing this error:
<script type="text/javascript">
function init() {
if(d.getElementById('normal')){
window.normalPop= d.getElementById('normal');
//complicated is local
var complicated= normalPop.parentNode.removeChild(normal);
d.getElementsByTagName('body')[0].appendChild(complicated);
}
}
addLoadEvent(init);
</script>
I am not sure why this error "SyntaxError: missing } in compound statement" is coming.The } braces are closing properly in the code.
If I am using innerHTML
instead of html()
it is working fine. No error is rendering.
The.html() uses .append() which inturn uses domManip() which does the script sniffing and execution. Because of this reason, the script code in coming from backend executed and caused this error "SyntaxError: missing } in compound statement". I investigated through the script code, the comment lines (//) in script code make commented some JS code too.So, after changing single line (//) to multi-line comments(/** **/).It get fixed.Thanks All for your time.
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