试图做一个简单的AJAX调用(自学)。我在与html
相同的文件夹中有一个.txt
文件。我在这里做错了什么?谢谢。示例AJAX调用不起作用
<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
$("#poo").submit(function(e){
e.preventDefault(); //stop submit
$.ajax({
type: "GET",
url: "data.txt",
data: "",
success: function(data){
$("#foo").html(data);
document.getElementById("foo").style.display = 'block';
alert('hey');
}
});
});
});
</script>
</head>
<body>
<form id="poo">
<input type="text"> </input>
<input type="submit"> </input>
</form>
<br>
<br>
<div style='display: none;'>
<p id="foo">this shows</p>
</div>
<a href="page.html">Start Over</a>
</body>
</head>
</html>
您是否在控制台中看到错误?你是在服务器上运行还是在本地计算机上运行? –
是的,在我的Chrome控制台:'未捕获的ReferenceError:$未定义'的第一行'$(document).ready(function(){' – Kervvv
您是否包含jQuery库? – Naterade