对于同样的问题,我也很沮丧。我正在从我的 ssl 页面发送 ajax 请求,如下所示:
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || 
$_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
<script type="text/javascript">
    $.ajax({ 
          url: "<?php echo $protocol.$_SERVER['HTTP_HOST'].$this->url(array("action"=>"autocomplete", "controller"=>"ajax", "module"=>"default"));?>",
                    data: { term: $("#keyword").val()},
                    dataType: "json",
                    type: "POST",
                    success: function(data){
                        response(data);
                    }
                });
</script>
问题是,请求标头显示引用页面是 ssl 页面,但响应标头显示位置为“http”页面,如 Rob 的代码打印屏幕上方所示。
我开始知道,每次当您从 ssl 页面响应发出 ajax 请求时,都会到达同一个页面,即 ssl 页面,而当您通过响应从非 ssl 页面发出 ajax 请求时,也会到达相同的页面,即非ssl页面。这是 ajax 请求和响应的默认规则。
我认为,我的代码方面肯定存在问题,它在从 https 发送时强制从 http 做出响应。没错,我的怀疑是对的。实际上有一个默认代码强制重定向到响应 http 页面而不是 https。我正在分享以前的代码:
    class Custom_Customplugins extends Zend_Controller_Plugin_Abstract
    {
        public function preDispatch(Zend_Controller_Request_Abstract $request)
        {
        $action = $request->getActionName();
        $controller = $request->getControllerName();
        $module = $request->getModuleName();
        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $host = $_SERVER['HTTP_HOST'];
        if($host != "www.xyz.com")
        {
            if($protocol == "http://")
            {
            }
        }
        else
        {
            $r = new Zend_Controller_Action_Helper_Redirector();
            $u = new Zend_Controller_Action_Helper_Url();
            if(
            ($action == "index" && $controller == "index" && $module == "default") 
            || ($action == "login" && $controller == "index" && $module == "default")
            || ($action == "businessownerregistration" && $controller == "index" && $module == "default")
            || ($action == "customerregistration" && $controller == "index" && $module == "default")
            || ($action == "index" && $controller == "changepwd" && $module == "admin") 
            || ($action == "index" && $controller == "businessowner" && $module == "businessowner") 
            || ($action == "changepwd" && $controller == "serviceprovider" && $module == "businessowner")
            || ($action == "index" && $controller == "customer" && $module == "default")    
              )
            {
            if($protocol == "http://")
            {
                $r->gotoUrl('https://'.$host.$u->url(array("action"=>$action, "controller"=>$controller, "module"=>$module)))->redirectAndExit();
            }
            }
            else
            {
            if($protocol == "https://")
            {
                $r->gotoUrl('http://'.$host.$u->url(array("action"=>$action, "controller"=>$controller, "module"=>$module)))->redirectAndExit();
            }
            }
        }
        }
    }
改正后代码如下:
<?php
    class Custom_Customplugins extends Zend_Controller_Plugin_Abstract
    {
        public function preDispatch(Zend_Controller_Request_Abstract $request)
        {
        $action = $request->getActionName();
        $controller = $request->getControllerName();
        $module = $request->getModuleName();
        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
        $host = $_SERVER['HTTP_HOST'];
        if($host != "www.xyz.com")
        {
            if($protocol == "http://")
            {
            }
        }
        else
        {
            $r = new Zend_Controller_Action_Helper_Redirector();
            $u = new Zend_Controller_Action_Helper_Url();
            if(
            ($action == "index" && $controller == "index" && $module == "default") 
            || ($action == "login" && $controller == "index" && $module == "default")
            || ($action == "businessownerregistration" && $controller == "index" && $module == "default")
            || ($action == "customerregistration" && $controller == "index" && $module == "default")
            || ($action == "index" && $controller == "changepwd" && $module == "admin") 
            || ($action == "index" && $controller == "businessowner" && $module == "businessowner") 
            || ($action == "changepwd" && $controller == "serviceprovider" && $module == "businessowner")
            || ($action == "index" && $controller == "customer" && $module == "default")    
              )
            {
            if($protocol == "http://")
            {
                $r->gotoUrl('https://'.$host.$u->url(array("action"=>$action, "controller"=>$controller, "module"=>$module)))->redirectAndExit();
            }
            }
            else if(
                ($action == "autocomplete" && $controller == "ajax" && $module == "default")
                || ($action == "refreshcaptcha" && $controller == "index" && $module == "default")
               )
            {
            }
            else
            {
            if($protocol == "https://")
            {
                $r->gotoUrl('http://'.$host.$u->url(array("action"=>$action, "controller"=>$controller, "module"=>$module)))->redirectAndExit();
            }
            }
        }
        }
    }
?>
现在,我的 https 页面工作正常