Nir*_*rni 6 javascript ajax json sharepoint-2013
这是我的代码,我已经包含了以下.js文件,onpage load它给出了错误"ReferenceError:CryptoJS未定义"为什么它在添加了js引用时会给出错误.我正在使用Office 365创建一个sharepoint-2013应用程序.
<script type="text/javascript" src="../Scripts/sha1.js"></script>
<script type="text/javascript" src="../Scripts/hmac-sha1.js"></script>
'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',
success: function (data) {
alert("IN Success");
alert(""+data.station_by_code);
},
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());
}
})();
Run Code Online (Sandbox Code Playgroud)
有两种形式可以解决此问题:
1:手动加载,我使用这种模式取得了更大的成功:
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js", execOperation);
}
);
Run Code Online (Sandbox Code Playgroud)
例子:
$.getScript("~hostUrl/_layouts/15/SP.RequestExecutor.js", getListDataREST);
Run Code Online (Sandbox Code Playgroud)
2:按需脚本:
SP.SOD.executeFunc('sp.userprofiles.js', 'SP.ClientContext', loadUserData);
Run Code Online (Sandbox Code Playgroud)
此 SharepointExchange 发布提供了大多数 AppPart 的常用 JSOM 实现:Jquery is not fire on Page load SharePoint 2013
| 归档时间: |
|
| 查看次数: |
24838 次 |
| 最近记录: |