我需要从服务器读取文本文件的内容并使用 JavaScript 解析内容,以便根据内容向页面添加元素。
但是,W3Schools的示例 在 FF12 中运行良好,但是如果我将示例左侧窗格中的源代码复制到 .html 文件,并在与我的 .html 相同的目录中创建所需的数据文件“demo_ajax_load.txt”,它不起作用。但是,它在 IE9 中可以正常工作。
这是来源:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$.get("demo_ajax_load.txt", function(result){
$("div").html(result);
});
});
});
</script>
</head>
<body>
<div><h2>Let AJAX change this text</h2></div>
<button>Change Content</button>
</body>
</html>