HTTPS连接是否禁用了jQuery?

JM4*_*JM4 12 javascript php https jquery

我有以下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>
Run Code Online (Sandbox Code Playgroud)

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

<?php
    session_start();

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

这些页面需要登录,所以我需要确保它们受https保护,但是这个错误会使所有这些都混乱.可能导致问题的任何想法?

Nic*_*ver 36

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

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

这样你会得到http://ajax.googleapis.com/....http://你的网页版本,并 https://ajax.googleapis.com/....https://版本.

  • 哇,我怎么不知道这件事?所有浏览器都支持此功能吗? (6认同)