2016-11-03 6 views
0

ThymeleafページでAjaxコールを作成しようとしています。だからここにコードエンティティ名は、エンティティ参照の '&'の直後に指定する必要があります。 javascript

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

があるので、それはエラーでcomplins:

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 ; 

2番目に&amp;

どのように処理できますか?

+0

を私は専門家だが、あなたはHTMLコメントでスクリプトコードをラップする可能性が私の知る限り、すなわち ' '。 – Thomas

+0

残念ながら、 '&'はJSの有効な演算子ではありません。これはHTMLエンティティです。 – evolutionxbox

+3

[エンティティ名はエンティティ参照の '&'の直後にある必要があります](http://stackoverflow.com/questions/16303779/the-entity-name- must- soonely-follow-the-in-the -entity-reference) – thatOneGuy

答えて

2

私は同様の問題がありましたが、私はscripting inlingをthymelefeafリファレンスドキュメントから追加して解決しました。

ので、次のように<script th:inline="javascript">の間、あなたの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> 
関連する問題