Jquery 如何允许在页面上显示不安全的内容

Jquery 如何允许在页面上显示不安全的内容,jquery,ajax,http-status-code-401,external-url,Jquery,Ajax,Http Status Code 401,External Url,我正在尝试向外部url发出AJAX请求,并尝试从该url获取Json数据。我得到401-授权错误,说它的内容不安全时,尝试访问url。下面是我的代码。请告知 function check() { var ENV_URL = 'http://../BlueLight/api/BlueLights/getActiveBlueLight'; $('#trBlueLight').hide(); $.getJSON(ENV_URL+"&callback=?", fu

我正在尝试向外部url发出AJAX请求,并尝试从该url获取Json数据。我得到401-授权错误,说它的内容不安全时,尝试访问url。下面是我的代码。请告知

function check() {

    var ENV_URL = 'http://../BlueLight/api/BlueLights/getActiveBlueLight';   
    $('#trBlueLight').hide();
    $.getJSON(ENV_URL+"&callback=?", function (data) {
        if (data.expDate != null) {
            $('#trBlueLight').show();
        } else {
            $('#trBlueLight').hide();
        }
    });
    }

因此,人们渴望得到评论。 我假设您创建了以下文件proxy\u loader.php,并将其放入您的Web服务器根目录(通常为httpdocs)。 它必须可以从

该文件应如下所示:

<?PHP

// get the url provided by javascriot
$url= $_GET['url'];

// initialize CURL
$ch = curl_init();

// additional headers like session id etc.
$header = '';

// optional user & password
$userpass = 'user:password';

//$parameters for the request
// use parameter name as array key
// use parameter value as array value
$param = array();

// set url
curl_setopt($ch, CURLOPT_URL, $url);
//this enables the output into a variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// set optional header
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// set request method to GET
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
// optional http authenfication
// remove the // to enable
// curl_setopt($ch, CURLOPT_USERPWD, $userpass);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);

// execute the request
// and save the response in $ret
$ret = curl_exec($ch);

// close the connection
curl_close($ch);

echo $ret;

// maybe you must use this:
// echo json_encode($ret);
?>
function check() {

    var ENV_URL = 'http://../BlueLight/api/BlueLights/getActiveBlueLight';   

    $('#trBlueLight').hide();

    $.getJSON('/proxy_loader.php?url=' + ENV_URL, function (data) {
        if (data.expDate != null) {
            $('#trBlueLight').show();
        } else {
            $('#trBlueLight').hide();
        }
    });
}

如果您可以在这两个域上放置代码,那么XDM很容易获得,代码示例

可以使用您的服务器请求内容。可以使用不安全的协议(http://而不是https://)启动页面,您可以使用apache mod_proxy将服务器作为代理,也可以使用Kevin B向服务器发送请求。PHP或其他服务器端语言将能够加载不安全的内容。但这可能会导致高流量!您能告诉我如何从我们的服务器向外部url请求内容吗。任何示例代码都会有帮助