Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code is giving error, "ReferenceError: CryptoJS is not defined" , while I have included required .js references, what's the reason?

Here is my code, I have included following .js files, onpage load it is giving error "ReferenceError: CryptoJS is not defined" why does it give that error when already js references are added. I am making a sharepoint-2013 app using office 365.

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

})();
like image 720
Niranjan Kulkarni Avatar asked Apr 09 '14 11:04

Niranjan Kulkarni


1 Answers

include core-min.js before sha256.js

like image 92
Mahendran Avatar answered Sep 18 '22 11:09

Mahendran