开发者

How can I import a text file into javascript from an external website using jquery $get()?

When the button in the following script gets clicked, it should load in the contents of the file "http://tanguay.info/knowsite/data.txt" and display it on the screen.

What is the correct syntaxt so that the .get() function retrieves the data from the external website and puts it in #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>


Have you thought of using jquery load

I put together a little code for a twitter app that loads a 2nd file with jquery load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜