这是我的代码,我包含了以下.js文件,在页面加载时,它给出了错误"ReferenceError: CryptoJS is not defined“,为什么它会在已经添加了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());
}
})();发布于 2015-09-24 19:59:49
在sha256.js之前包括core-min.js
发布于 2014-04-09 21:57:04
修复此问题有两种形式之一:
1:手动加载,我使用这个模式更成功:
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js", execOperation);
}
);示例:
$.getScript("~hostUrl/_layouts/15/SP.RequestExecutor.js", getListDataREST);2:按需编写脚本:
SP.SOD.executeFunc('sp.userprofiles.js', 'SP.ClientContext', loadUserData);这篇SharepointExchange文章给出了大多数AppParts的常用JSOM实现:Jquery is not firing on Page load SharePoint 2013
发布于 2014-04-10 16:44:33
错误解决了,我添加了在线参考,
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>https://stackoverflow.com/questions/22960747
复制相似问题