代码之家  ›  专栏  ›  技术社区  ›  Edward Tanguay

如何使用jquery$get()将文本文件从外部网站导入到javascript中?

  •  1
  • Edward Tanguay  · 技术社区  · 15 年前

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

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

    <!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>
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   Hellonearthis    15 年前

    你想过用吗 jquery load

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