【问题标题】:the entity name must immediately follow the '&' in the entity reference. javascript实体名称必须紧跟实体引用中的“&”。 javascript
【发布时间】:2016-11-03 09:52:13
【问题描述】:

我正在尝试在我的 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;amp; 更改为&amp;amp;,现在看起来像:

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

但现在它再次抱怨:

Uncaught SyntaxError: Unexpected token ;

在第二个&amp;amp;

我该如何处理?

【问题讨论】:

标签: javascript html thymeleaf


【解决方案1】:

我遇到了类似的问题,我已经解决了从 thymelefeaf 参考文档中添加 scripting inling 的问题。

因此,尝试将您的 javascript 代码放在 &lt;script th:inline="javascript"&gt; 之间,如下所示:

<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>

【讨论】:

    猜你喜欢
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多