jQuery:加载txt文件并插入到div中 [英] jQuery: load txt file and insert into div

查看:54
本文介绍了jQuery:加载txt文件并插入到div中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载一个 *.txt 文件并将内容插入到一个 div 中.这是我的代码:

js:

$(document).ready(function() {$("#lesen").click(function() {$.ajax({url : "helloworld.txt",成功:功能(数据){$(".text").html(数据);}});});});

html:

<input type="button" id="lesen" value="Lesen!"/>

<div class="text">Lorem Ipsum <br/>

txt:

我完成了

如果我点击按钮 firebug 报告以下错误:

语法错误我受够了

我不知道该怎么办:-(

解决方案

你需要添加一个 dataType - http://api.jquery.com/jQuery.ajax/

$(document).ready(function() {$("#lesen").click(function() {$.ajax({url : "helloworld.txt",数据类型:文本",成功:功能(数据){$(".text").html(数据);}});});});

I want to load a *.txt file and insert the content into a div. Here my code:

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>

txt:

im done

If i click on the button firebug report following error:

Syntax-Error
im done

I don´t know what to do :-(

解决方案

You need to add a dataType - http://api.jquery.com/jQuery.ajax/

$(document).ready(function() {
    $("#lesen").click(function() {
        $.ajax({
            url : "helloworld.txt",
            dataType: "text",
            success : function (data) {
                $(".text").html(data);
            }
        });
    });
}); 

这篇关于jQuery:加载txt文件并插入到div中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆