0

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

1 回答 1

0

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

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

不要从 HTTPS 页面向 HTTP 端点发出 Ajax 请求。数据不安全,可能被截获并可能危及页面的安全性(特别是如果 JSONP 用于跨域请求)。

于 2014-04-10T09:19:33.687 回答