HTTPS 连接是否禁用了 jQuery?

发布于 2024-10-01 07:58:26 字数 2976 浏览 2 评论 0原文

我有以下 php 脚本,在正常情况下可以完美运行(即直接访问页面):

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/contact_search.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.watermarkinput.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$(document).click(function() {
    $("#display").hide();
});

var cache = {};

    $("#searchbox").keyup(function() {
        var searchbox = $(this).val();
        var dataString = 'searchword=' + searchbox;

        if (searchbox.length < 3 ) {
            $("#display").hide();
            } else {

            $.ajax({
                type: "POST",
                url: "contact_search/search.php",
                data: dataString,
                cache: false,
                success: function(html) {

                    $("#display").html(html).show();
                }
            });
        return false;
    });
});

jQuery(function($) {
    $("#searchbox").Watermark("Search for Group");
});
</script>
</head>

<body bgcolor="#e0e0e0">
<div class="body">


          <div class="liquid-round" style="width:100%;">
            <div class="top"><span><h2>Contacts List</h2></span></div>

            <div class="center-content"> 
                <img src="images/search.gif" style="float:right;" />
                <input type="text" id="searchbox" maxlength="20" value="<?php echo $_SESSION['hello'];?>" />
                <div id="display"></div><div style="clear:both;"></div>

            </div>

            <div class="bottom"><span></span></div>
        </div>


        <div class="liquid-round" style="width:97%;">
            <div class="top"><span><h2>My Messages</h2></span></div>

            <div class="center-content" style="min-height:200px;">                        
            </div>

            <div class="bottom"><span></span></div>
        </div>    


</div>
</body>
</html>

但是 - 当我将以下代码添加到页面顶部时,javascript/jquery 函数完全停止工作。

<?php
    session_start();

    if( $_SERVER['SERVER_PORT'] == 80) {
        header('Location:https://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); 
        die();
    }
?>

这些页面需要登录,所以我需要确保它们受到 https 保护,但这个错误搞乱了这一切。有什么想法可能导致这个问题吗?

I have the following php script which works flawlessly in normal circumstances (i.e. visiting the page directly):

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/contact_search.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.watermarkinput.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$(document).click(function() {
    $("#display").hide();
});

var cache = {};

    $("#searchbox").keyup(function() {
        var searchbox = $(this).val();
        var dataString = 'searchword=' + searchbox;

        if (searchbox.length < 3 ) {
            $("#display").hide();
            } else {

            $.ajax({
                type: "POST",
                url: "contact_search/search.php",
                data: dataString,
                cache: false,
                success: function(html) {

                    $("#display").html(html).show();
                }
            });
        return false;
    });
});

jQuery(function($) {
    $("#searchbox").Watermark("Search for Group");
});
</script>
</head>

<body bgcolor="#e0e0e0">
<div class="body">


          <div class="liquid-round" style="width:100%;">
            <div class="top"><span><h2>Contacts List</h2></span></div>

            <div class="center-content"> 
                <img src="images/search.gif" style="float:right;" />
                <input type="text" id="searchbox" maxlength="20" value="<?php echo $_SESSION['hello'];?>" />
                <div id="display"></div><div style="clear:both;"></div>

            </div>

            <div class="bottom"><span></span></div>
        </div>


        <div class="liquid-round" style="width:97%;">
            <div class="top"><span><h2>My Messages</h2></span></div>

            <div class="center-content" style="min-height:200px;">                        
            </div>

            <div class="bottom"><span></span></div>
        </div>    


</div>
</body>
</html>

HOWEVER - when I add the following piece to the top of the page, the javascript/jquery functions simply stop working altogether.

<?php
    session_start();

    if( $_SERVER['SERVER_PORT'] == 80) {
        header('Location:https://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); 
        die();
    }
?>

These pages require login so I need to ensure they are https protected but this error messes all that up. Any ideas what could be causing the issue?

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

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

发布评论

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

评论(2

爱本泡沫多脆弱 2024-10-08 07:58:26

这可能是浏览器没有在 https 页面上显示不安全的 (http) 内容,不过有一个简单的修复方法,使用方案相对 URL,如下所示:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>

这样您将获得 http://ajax.googleapis.com/。 ... 在您页面的 http:// 版本上,以及 https://ajax.googleapis.com/....>https:// 版本。

It's probably the browser not displaying insecure (http) content on https pages, there's a simple fix though, use a scheme relative URL, like this:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>

This way you'll get http://ajax.googleapis.com/.... on the http:// version of your page and https://ajax.googleapis.com/.... on the https:// version.

心是晴朗的。 2024-10-08 07:58:26

由于 session_start 会生成 HTTP 标头,因此我建议在 session_start 之前进行端口检查。

但是,这些行在任何情况下都不应该影响您的 JS,因为重定向到 HTTPS 与您的网站是否通过 HTTPS 工作这一事实无关。因此,如果您不确定,请删除这些行并使用 HTTPS 访问您的页面。带JS去那里工作。然后实施重定向。

Since session_start produces HTTP-Headers I recommend to do the port check before session_start.

But, these lines should not affect your JS in any circumstances, because the redirect to HTTPS is independend from the fact if your site is working via HTTPS. So, if you are not sure, remove the lines and access your page with HTTPS. Bring JS to work there. And afterwards implement the redirect.

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