Jquery 中的 Ajax 不适用于本地文件 [英] Ajax in Jquery does not work from local file

查看:31
本文介绍了Jquery 中的 Ajax 不适用于本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用简单的ajax创建了简单的html文件.

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>

文件 2.html 与文件 index.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>

当我在网络服务器上运行 index.html 时,一切正常.但是如果你在计算机上运行文件 index.html 作为本地文件 ajax 不起作用.如何解决?

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?

推荐答案

这是 Chrome 的一个已知问题,如果您正在检查它.使用 XAMPP 运行本地网络服务器,并测试您的 ajax 调用.

This is a known problem with Chrome, if you are checking on it. Use XAMPP to run a local webserver, and test your ajax call.

检查这张票:https://code.google.com/p/chromium/issues/detail?id=40787

这篇关于Jquery 中的 Ajax 不适用于本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆