0

这是我的代码我试图从 HTTPS 页面访问 HTTP 页面上的内容它在浏览器控制台中给我一个错误,它是一个不安全的内容,以下是一个错误“在安全页面上加载混合(不安全)活动内容" http://pnrbuddy.com/api/station_by_code/code/cnb/format/json/pbapikey/539ff0f815ca697c681fe01d32ba52e3/pbapisign/906544ca31f9c0048e80bde8127556af828e313b " ' 显示 Json 浏览器控制台但无法读取。我怎样才能读取那个 JSON?

'use strict';

var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();

(function () {

    // This code runs when the DOM is ready and creates a context object which is 
    // needed to use the SharePoint object model
    $(document).ready(function () 
    {
        getUserName();

        $("#button1").click(function()
        {
                paraupdate();   
        });

    });

    // This function prepares, loads, and then executes a SharePoint query to get 
    // the current users information

    function paraupdate()
    {

        var str=""+$("#textbox1").val();
        alert(""+str);
        var message = str+"json539ff0f815ca697c681fe01d32ba52e3";
        var secret = "<my private key>";
        var crypto = CryptoJS.HmacSHA1(message, secret).toString();
        alert("crypto answer is " + crypto);
        var siteurl="http://pnrbuddy.com/api/station_by_code/code/"+str+"/format/json/pbapikey/539ff0f815ca697c681fe01d32ba52e3/pbapisign/"+crypto;


        //////////////////////////////////////////////
         $.ajax({
            url: siteurl,
            type: "GET",
            dataType: 'json',
    /*  headers: {
                "accept": "application/json;odata=verbose",
            },   */
            success: function (data) {
                alert("Success");
                alert(data.Station);
            /*  $.each(data.d.results, function (index, item) 
                {     

                   alert("My ID"+index);
                    alert("Item"+item);
                });

                //var str=JSON.parse(data);

                 var myResults = [];
            $.each(data, function (index, item) {
                alert("dsfsd"+item.station_by_code)
                myResults.push({
                    id: item.id,  

                    //text: item.first_name + " " + item.last_name
                }); 
            });     */

            },
            error: function (error) {
                alert("IN Error");
                alert(JSON.stringify(error));
            }
        });
        /////////////////////////////////////////////

    }

    function getUserName() 
    {
        context.load(user);
        context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
    }

    // This function is executed if the above call is successful
    // It replaces the contents of the 'message' element with the user name
    function onGetUserNameSuccess() 
    {
        $("#label1").html("Enter Station Code : ");
        $("#button1").val("CLICK");

    }

    // This function is executed if the above call fails
    function onGetUserNameFail(sender, args) {
        alert('Failed to get user name. Error:' + args.get_message());
    }



})();
4

1 回答 1

-2

'使用严格';

var context = SP.ClientContext.get_current(); var user = context.get_web().get_currentUser();

(功能 () {

// This code runs when the DOM is ready and creates a context object which is 
// needed to use the SharePoint object model
$(document).ready(function () 
{
    getUserName();

    $("#button1").click(function()
    {
            paraupdate();   
    });

});

// This function prepares, loads, and then executes a SharePoint query to get 
// the current users information

function paraupdate()
{

    var str=""+$("#textbox1").val();
    alert(""+str);
    var message = str+"json539ff0f815ca697c681fe01d32ba52e3";
    var secret = "<my private key>";
    var crypto = CryptoJS.HmacSHA1(message, secret).toString();
    alert("crypto answer is " + crypto);
    var siteurl="http://pnrbuddy.com/api/station_by_code/code/"+str+"/format/json/pbapikey/539ff0f815ca697c681fe01d32ba52e3/pbapisign/"+crypto;


    //////////////////////////////////////////////
     $.ajax({
        url: siteurl,
        type: "GET",
        dataType: 'json',
        success: function (data) {
            alert("Success");
            alert(" Code : "data.stations[0].code+" Name : "+data.stations[0].name);

        },
        error: function (error) {
            alert("IN Error");
            alert(JSON.stringify(error));
        }
    });
    /////////////////////////////////////////////

}

function getUserName() 
{
    context.load(user);
    context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
}

// This function is executed if the above call is successful
// It replaces the contents of the 'message' element with the user name
function onGetUserNameSuccess() 
{
    $("#label1").html("Enter Station Code : ");
    $("#button1").val("CLICK");

}

// This function is executed if the above call fails
function onGetUserNameFail(sender, args) {
    alert('Failed to get user name. Error:' + args.get_message());
}

})();

于 2014-04-15T06:04:20.340 回答