以下是我的代码,我想获取JSON数据,我正在办公室365 Napa做一个铁路应用程序,我的JSON正在加载但没有向我显示数据,我正在传递的站点代码通过在URL中传递HMAC签名生成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": {
"lat": "26.4279135",
"lng": "80.3604594"
},
"about_text": null,
"about_link": null
}
]
}
答案 0 :(得分:0)
您正在尝试提醒data.message
,但您的JSON没有message
属性。查看数据中实际存在的属性。
在安全页面上加载混合(不安全)活动内容
不要从HTTPS页面向HTTP端点发出Ajax请求。数据不安全,可能被截获并可能危及页面的安全性(特别是如果JSONP用于跨源请求)。