我是ajax和jquery的新手。我正在尝试将一个简单的.txt文件加载到div中以便进行测试。但我不断收到错误(未定义)。我的txt文件和html文件在同一目录中。我甚至试图给出完整的路径但是工作。以下是我的代码段
<html>
<script type = "text/javascript"
src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script
<body>
<link rel = "stylesheet" href = "shop.css">
<div id = "header">
<p id = "welcome"> SHOPPINGCART.COM </p>
</div>
<div id = "container">
hi
<div class = "image">
<div class = "pic">
<img src ="images/item.jpg">
</div>
<div class = "label">
<p1> Item 1 </p1>
<p2> Price </p2>
<button type = "button" class = "add">
Add
</button>
</div>
</div>
<div class = "image">
<div class = "pic">
<img src ="images/item.jpg">
</div>
<div class = "label">
<p1> Item 1 </p1>
<p2> Price </p2>
<button type = "button" class = "add">
Add
</button>
</div>
<script>
$("button").click(function(event) {
$("#welcome").load("test.txt", function(responseTxt, statusTxt, xhr) {
if (statusTxt == "success")
alert("External content loaded successfully!");
if (statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.responseTxt);
});
//$(event.target).html("Added");
});
</script>
</body>
</html>