繁体   English   中英

无法使用jquery和html加载文本文件

[英]Not able to load a text file using jquery and html

<script type="text/javascript">
        $(document).ready(function () {
            $("#readFile").click(function () {
                debugger;
                $.get(ServerUrl + "/Vi/Gr/abcd.txt", function (data) {
                    $("#container").html(data);
                }, 'text');

                //$(".text").load(ServerUrl + "/Gr/abcd.txt");

                //$("#container").load(ServerUrl + "/Vi/Gr/abcd.txt");
            });
        });
    </script>



    <button id="readFile" style="margin-top:50px;">Read File</button>

    <div id="container" style="border-style:solid;height:300px;"></div>

上面是我的代码,用于使用jquery和html读取文件的内容。 我不断收到找不到文件的错误和其他错误。 例如

Uncaught TypeError: Cannot read property 'apply' of undefined.

我做错了。 请帮忙。

从您提供的信息很难说。

根据文件的位置,可能是因为文件路径错误。 您确定文件在那里吗? 另一个可能的原因是您的服务器不知道如何响应该URL。 您的服务器正在运行什么?

此外,javascript实际上无法直接下载文件。 查看其他答案,例如通过jQuery.Ajax下载文件。

请提供所有错误以及有关服务器运行方式的更多详细信息,因为根据此处给出的详细程度很难回答您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM