实体名称必须紧跟在'&'在实体引用中.javascript

the entity name must immediately follow the '&' in the entity reference. javascript

本文关键字:实体 引用 javascript      更新时间:2023-09-26

我正在尝试在我的Thymeleaf页面中进行Ajax调用。这里是代码

<script>
        function getTodayRequest(){
            console.log("here is today");
            var xhttp=new XMLHttpRequest();
            xhttp.onreadystatechange=function(){
                if(this.readyState==4 && this.status==200){
                document.getElementById("received").innerHTML=
                    this.responseText;
                }
            };
            xhttp.open("GET","URI",true);
        }
</script>

因此出现了错误:

the entity name must immediately follow the '&' in the entity reference. java

和我已经改变了&&amp;,现在它看起来像:

if(this.readyState==4 &amp;&amp; this.status==200)

但是现在它又抱怨了:

Uncaught SyntaxError: Unexpected token ;

第二个&amp;

我该如何处理?

我有一个类似的问题,我已经解决了从thymelefeaf参考文档中添加scripting inling

所以,试着把你的javascript代码放在<script th:inline="javascript">之间,像下面:
<script th:inline="javascript">
/*<![CDATA[*/
     function getTodayRequest(){
            console.log("here is today");
            var xhttp=new XMLHttpRequest();
            xhttp.onreadystatechange=function(){
                if(this.readyState==4 && this.status==200){
                document.getElementById("received").innerHTML=
                    this.responseText;
                }
            };
            xhttp.open("GET","URI",true);
        }
/*]]>*/
</script>