2016-12-09 71 views
0

我需要調用JavaScript函數inn thymeleaf,並且由於函數未定義而出現錯誤。 這裏是我的代碼在thymeleaf調用javascript函數

<div class="input-field col s6 m6"> 
     <input id="isbn" name="isbn" type="text" class="validate" /> 
     <label for = "isbn">Enter ISBN Code</label> 
</div> 
    <div class="input-field col s6 m6"> 
     <button id="submitCode" class="btn waves-effect waves-light col m4" th:onclick="'javascript:myFunction();'" value="data">ISBN Data</button> 
    </div> 

JavaScript代碼

function myFunction() 
{ 
    var isbn = document.getElementById('isbn').value; 
    alert(isbn); 
    var xmlhttp = new XMLHttpRequest(); 
    var url = "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn; 
    xmlhttp.onreadystatechange = function() 
    { 
     if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) 
     { 
      var x = JSON.parse(xmlhttp.responseText); 
      callback(x); 
     } 
    }; 
    xmlhttp.open("GET", url, true); 
    xmlhttp.send(); 
} 
function callback(x) 
{ 
    //do things with your data here 
    alert(JSON.stringify(x)); 
    console.log(x); 
} 
+0

請分享完整的錯誤日誌,這將有助於查明問題。 –

回答