jQuery $.load() 在个人网络服务器上运行,但在生产网络服务器上不起作用

发布于 2024-08-08 14:44:08 字数 1324 浏览 3 评论 0原文

编辑:我发现这是一个 405 错误。因此,网络服务器和处理 POST 方法发生了一些事情。

我遇到了一个奇怪的现象。我的测试环境和生产环境都有相同的 JavaScript 代码。

测试环境可以运行,而生产环境则不能。这是我的相同代码。

<html>
    <head>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript" src="http://cdn.jquerytools.org/1.1.2/jquery.tools.min.js"></script>
      <script type="text/javascript" src="./js/jquery.scrollTo-min.js"></script>
    </head>
    <body>
      <div class="content" id="content"> 
        <a id="changeText" href="test.html">Change</a>
      </div>

      <script>
         $(document).ready(function() {

            $("#changeText").live('click', function(){

                var url = $(this).attr("href");

                $("#content").load(url, {var1:Math.random()*99999},function(){

                     alert(url + " loaded");
                });

                $.scrollTo("0%", 400);

              return false;
            });
        });
     </script>
    </body>
</html>

两种环境都报告

alert(url + " loaded");

正在发生这种情况。但只有我的测试环境真正显示了变化。

生产网络服务器在正确的位置有可用的“test.html”。

EDIT: I have discovered that this is a 405 error. So there is something going on with the webserver and handling POST methods.

I am having a strange occurrence. I have identical javascript code on both my test environment and production environment.

The test environment functions, and the production does not. Here is my identical code.

<html>
    <head>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript" src="http://cdn.jquerytools.org/1.1.2/jquery.tools.min.js"></script>
      <script type="text/javascript" src="./js/jquery.scrollTo-min.js"></script>
    </head>
    <body>
      <div class="content" id="content"> 
        <a id="changeText" href="test.html">Change</a>
      </div>

      <script>
         $(document).ready(function() {

            $("#changeText").live('click', function(){

                var url = $(this).attr("href");

                $("#content").load(url, {var1:Math.random()*99999},function(){

                     alert(url + " loaded");
                });

                $.scrollTo("0%", 400);

              return false;
            });
        });
     </script>
    </body>
</html>

Both environments report that

alert(url + " loaded");

is happening. But only my test environment actually displays the change.

The production webserver has "test.html" available in the correct location.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

同尘 2024-08-15 14:44:09

确定生产服务器上包含了scrollTo脚本(还是我误解了您所说的change的含义)?也许尝试使用根相对路径而不是“./js”?我会检查 Firebug 的脚本选项卡以确保它被包含在内。

Are you sure the scrollTo script is being included on the production server ( or am I misinterpreting what you mean by change ) ? Perhaps try a root relative path instead of './js'? I would check Firebug's script tab to ensure it is being included.

淤浪 2024-08-15 14:44:09

405 错误意味着您要发送到的 URL 不希望您以这种方式发送数据。例如,如果您向仅设计用于处理 GET 请求的 URL 发送 POST 请求,您将收到此错误。

我的猜测是,您运行的任何服务器都设置为不允许将 POST 数据发送到扩展名为 .html 的页面,从而导致您看到的错误。尝试将扩展名更改为 .php、.aspx 等,看看是否有帮助。

405 errors mean that the URL you're sending to isn't expecting you to send the data in that manner. For example, if you're sending a POST request to a URL that's only designed to handle a GET request, you'll get this error.

My guess is whatever server you're running on is set up to not allow POST data to be sent to a page with a .html extension, causing the error you're seeing. Try changing the extension to a .php, .aspx, etc, and see if that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文