我想加载一个 *.txt 文件并将内容插入到一个 div 中。 这是我的代码:
js:
$(document).ready(function() {
$("#lesen").click(function() {
$.ajax({
url : "helloworld.txt",
success : function (data) {
$(".text").html(data);
}
});
});
});
html:
<div class="button">
<input type="button" id="lesen" value="Lesen!" />
</div>
<div class="text">
Lorem Ipsum <br />
</div>
文本:
im done
如果我点击按钮 Firebug 报告以下错误:
Syntax-Error
im done
我不知道该怎么办:-(
最佳答案
您需要添加一个数据类型 - http://api.jquery.com/jQuery.ajax/
$(document).ready(function() {
$("#lesen").click(function() {
$.ajax({
url : "helloworld.txt",
dataType: "text",
success : function (data) {
$(".text").html(data);
}
});
});
});
关于javascript - jQuery:加载txt文件并插入div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6470567/