Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

html - Ajax in Jquery does not work from local file

I created simple html file with simple ajax.

index.html:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; Charset=UTF-8">
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
    <div id="content"></div>

    <script>
        function show()
        {
                $.ajax({
                url: "2.html",
                cache: false,
                success: function(html){
                    $("#content").html(html);
                }
            });
        }

        $(document).ready(function(){
            show();
            setInterval('show()',1000);
        });
    </script>

</body>
</html>

File 2.html located in the same directory as the file index.html. And contains for example:

 <p>ssss hkl jh lkh <b>d1111</b></p>

When I run the index.html on the webserver, everything works. But if you run file index.html on the computer as a local file ajax not working. How to fix it?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Some browsers implement strong security measures to prevent downloaded webpages from accessing arbitrary files on the file system.

Switch to a browser with weaker security (I think Firefox permits access to local files via XHR) or stop trying to run a website without HTTP.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...