我没有得到JSON数据,尽管它被正确加载了,为什么会发生这种情况?它显示一个空白的警告框

I am not getting the JSON data, though it is getting loaded properly, why does that happen so? It is showing blank alert box

本文关键字:显示 情况 警告 空白 一个 为什么 JSON 数据 加载      更新时间:2023-09-26

以下是我的代码,我想获得JSON数据,我正在office 365 Napa中做一个铁路应用程序,我的JSON正在加载,但没有向我显示数据,我通过在URL中传递生成HMAC签名的字符串中传递的站代码,我得到了我必须读取的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;

        $.getJSON(
          siteurl,
          function(data){
              alert(data.message);
              });
    }

    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());
    }

})();

JSON响应为:

{
    "response_code": 200,
    "stations": [
        {
            "name": "Kanpur Central",
            "code": "CNB",
            "state": "UP",
            "zip": null,
            "railway_zone": "",
            "location": {
                "lat‌​": "26.4528466",
                "lng": "80.3237478"
            },
            "about_text": null,
            "about_link": null
        },
        {
            "name": "‌​Chandari",
            "code": "CNBI",
            "state": "UP",
            "zip": null,
            "railway_zone": "",
            "location": {
                "la‌​t": "26.4279135",
                "lng": "80.3604594"
            },
            "about_text": null,
            "about_link": null
        }
    ]
}

您正试图提醒data.message,但您的JSON没有message属性。查看数据中实际存在的属性。

在安全页面上加载混合(不安全)活动内容

不要从HTTPS页面向HTTP端点发出Ajax请求。数据不安全,可能会被拦截,并可能危及页面的安全性(尤其是在JSONP用于跨源请求的情况下)。