5

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.

4

1 に答える 1

2

.html() は、スクリプトのスニッフィングと実行を行う domManip() を使用する .append() を使用します。このため、バックエンドからのスクリプト コードが実行され、このエラー「SyntaxError: missing } in complex statement」が発生しました。スクリプトコードを調べたところ、スクリプトコードのコメント行 (//) は一部の JS コードにもコメントを付けています。修正しました。お時間をいただきありがとうございます。

于 2013-02-04T10:41:18.423 に答える