【发布时间】:2017-04-25 10:34:26
【问题描述】:
我需要调用一个 javascript 函数 inn thymeleaf,但由于未定义函数而出现错误。 这是我的代码
<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 && 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);
}
【问题讨论】:
-
请分享完整的错误日志,这将有助于识别问题。
标签: javascript html onclick thymeleaf