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

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

问题描述

我想加载一个* .txt文件和其内容插入到一个div。 在这里,我的code:

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

记者:

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

HTML:

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 :-(

推荐答案

您需要添加一个数据类型 - 的http:// API .jquery.com / jQuery.ajax /

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天全站免登陆