zoukankan      html  css  js  c++  java
  • ajax读取文本内容(此处的txt文件和html文件处于同级目录)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8" />
    <style>
    </style>
    <title>read file</title>
    </head>
    <script src="jquery-1.11.2.js"></script>
    <script>
    
                $(function() {
                    $("#btn1").click(function(){
                        $.ajax({
                            type: "get",
                            url: "1.txt",
                            dataType: "text",
                            async: true
                        }).done(function (data) {
                            $("#one").html(data.replace(/
    /ig, '</br>'));//替换回车行成换行符
                            //console.log(data.replace(/
    /ig,'</br>'));
                        });
                    });
                });
            </script>
        <body>
            <div id="one" style=" 300px;background: greenyellow;margin: 10px;;">
            </div>
            <input type="button" id="btn1" value="点击获取"/>
        </body>
    </html>
  • 相关阅读:
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    软件测试
    When:什么时候做集成测试
  • 原文地址:https://www.cnblogs.com/ch-n/p/6255716.html
Copyright © 2011-2022 走看看