【问题标题】:Error: The ajax javascript file could not be loaded. Perhaps the URL is incorrect?错误:无法加载 ajax javascript 文件。也许网址不正确?
【发布时间】:2019-10-01 10:39:48
【问题描述】:

生成用户报告时出现以下错误

错误:无法加载 ajax javascript 文件。也许是网址 是不正确的?

网址:site.com/js/xajax.js

在控制台中我看到以下消息:

function xajax_getReport(){return xajax.call("getReport", arguments, 1);}

获取报表函数:

public function getReport() {
    $xajaxResponse = new xajaxResponse();

    $this->template->assign("report", true);
    $user =& User::getInstance();

    //$this->template->assign("calendarMode", "noactive");
    if ($user) {
        $today = date("Y-m-d H:i:s");
        //$doctor = $user->getDoctor();
        //$doctorSettings = $doctor->getDoctorSettings();   
        //if ($doctorSettings->getTestTour() == 2) $this->template->assign("showAA", true);

        if ($user->getSubscriptionDueDate() < $today) {
            $this->template->assign("notlogin", true);
            //$this->template->assign("doctor", $doctor);
        }
    }       

//      $user = User::getInstance();
//        exit('here');
    $doctor = $user->getDoctor();
    $userState = $user->getState();
    $doctorSettings = $doctor->getDoctorSettings();
    if ($doctorSettings->getQuizType(1)) $this->template->assign('showBasic',1);
    $states = $doctor->getStateArray();
    $stateShow = false;
    foreach ($states as $state) {
        if ($state == $userState) {
            $stateShow = true;
            break;
        }
    }

    $this->template->assign("user", $user);
    $this->template->assign("doctor", $doctor);
    $this->template->assign("stateShow", $stateShow);
    $this->template->assign("date",$_SESSION["date"]);

    if (file_exists("flash/{$user->getId()}/{$_SESSION["date"]}/paramArray")){
        $lastReportParams = Patient::getReportParams($user->getId(),$_SESSION["date"]);
        $allow = $lastReportParams["allow"][(NA_SITE?NA:WLA)];
    }
    else $allow = ($doctor->getShowGraph()==2)?in_array($user->getState(),$doctor->getShowGraphStatesCode()):$doctor->getShowGraph();
    $this->template->assign("allow", $allow);

    //allow user to view the report or not
    $date = $_SESSION['thedate'];
    if (file_exists("flash/{$user->getId()}/{$date}/allow")){
        //$this->template->assign("date", $_SESSION['date']);
        $this->template->assign("allow", true);
    }

    $content = $this->renderTemplate("patient/test_result.tpl");

    $xajaxResponse->addAssign("cont", "innerHTML", $content);
    $xajaxResponse->addAssign("loader", "style.display", "none");
    $exJS = HttpSession::get("exJS");
    $errors = HttpSession::get("errors");
    if ($errors)
        $xajaxResponse->script("document.getElementById('pr_rep_ref').style.display = 'none';
        document.getElementById('pr_rep').style.display = 'none';");
    $xajaxResponse->script(HttpSession::get("exJS"));
//      $xajaxResponse->addScriptCall("createFlash", "");


    return $xajaxResponse->getXML();
}   

【问题讨论】:

    标签: javascript codeigniter


    【解决方案1】:

    xajax 脚本通过 HTTP 而不是 HTTPS 加载 Chrome 现在会阻止该脚本,因为您在 HTTPS 环境中运行。

    您可以通过在 htaccess 中设置 hsts 标头来临时解决此问题

    .htaccess

    Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
    Header set Content-Security-Policy "upgrade-insecure-requests"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
    

    更多信息:https://stackoverflow.com/a/56063975/5265084

    【讨论】:

    • 通过将以上行添加到 htaccess 现在它抛出 500 内部服务器错误
    • 你是在使用 apache、nginx 还是其他东西作为 webserver?
    • Apache/2.2.15 (CentOS)
    • 我更改了 sn-p,再试一次。如果它不起作用,您应该找到通过 HTTP 加载的脚本
    猜你喜欢
    • 1970-01-01
    • 2017-12-11
    • 2017-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2020-06-01
    相关资源
    最近更新 更多