【问题标题】:How can I import a text file into javascript from an external website using jquery $get()?如何使用 jquery $get() 从外部网站将文本文件导入 javascript?
【发布时间】:2010-04-28 03:50:07
【问题描述】:

当点击以下脚本中的按钮时,它应该加载文件“http://tanguay.info/knowsite/data.txt”的内容并显示它在屏幕上。

.get() 函数从外部网站检索数据并将其放入#content 中的正确语法是什么?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript"
        src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("jquery", "1.3.2");
            google.setOnLoadCallback(function() {
                $('#loadButton').click(loadDataFromExernalWebsite);
            });
            function loadDataFromExernalWebsite() {
                $('#content').html('new content');
                //$.get("http://tanguay.info/knowsite/data.txt", function(data) { alert(data); }, );
            }
        </script>
    </head>
<body>
    <p>Click the button to load content:</p>
    <p id="content"></p>
    <input id="loadButton" type="button" value="load content"/>
</body>
</html>

【问题讨论】:

标签: javascript jquery get


【解决方案1】:

你有没有想过使用jquery load

我将 a little code for a twitter app that loads 与 jquery 加载的第二个文件放在一起。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-21
  • 1970-01-01
  • 2011-03-10
相关资源
最近更新 更多