这是我的代码..我在控制台收到Uncaught TypeError错误:$ .get(...)。然后不是函数。.error位于第18行
<button class="btn btn-primary" id="requestButton">HTTP Request</button>
<ul id="myList"></ul>
<script type="text/javascript">
var ulElm = document.querySelector("#myList");
var first = false;
var chatList;
function updateChat() {
console.log("update Chat called");
$.get("http://projecttester.16mb.com/makejson.php")
.then(function(data) {//ERROR IS IN THIS LINE
if(!first) {
chatList = JSON.parse(data);
chatList.forEach(function(item) {
var liElm = document.createElement('li');
liElm.innerHTML = item.Message;
ulElm.appendChild(liElm);
});
</script>
</body>
最佳答案
尝试使用-
<button class="btn btn-primary" id="requestButton">HTTP Request</button>
<ul id="myList"></ul>
<script type="text/javascript">
var ulElm = document.querySelector("#myList");
var first = false;
var chatList;
function updateChat() {
console.log("update Chat called");
$.get("http://projecttester.16mb.com/makejson.php", function(data) {
if(!first) {
chatList = JSON.parse(data);
chatList.forEach(function(item) {
var liElm = document.createElement('li');
liElm.innerHTML = item.Message;
ulElm.appendChild(liElm);
}
}
});
}
</script>
</body>