2015-11-02 110 views
0

我想加密密码并通过Ajax调用帖子将其存储在Mongo LAB上。 我收到以下错误: 我搜索了错误,但没有得到它是什么意思,它是指向循环。 错误:无法通过ajax调用发送Crypto JS加密数据

TypeError: Converting circular structure to JSON 
    at Object.stringify (native) 
    at n.$scope.signup (file:///C:/Users/naval.joshi/Desktop/eWallet/Assignment/Assignment/register.js:26:32) 
    at fn (eval at <anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:212:409), <anonymous>:4:209) 
    at f (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:253:485) 
    at n.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:133:221) 
    at n.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:133:451) 
    at HTMLButtonElement.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:254:36) 
    at HTMLButtonElement.Hf.c (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:35:217) 

代码:

var reg = angular.module('register', ['ngRoute']); 
reg.controller('regCntrl', function($scope,$http) { 
    $scope.signup = function() { 

     $scope.encryptedData = CryptoJS.AES.encrypt($scope.password, "123"); 
     alert($scope.encryptedData); 

     //alert("naval"); 

         var inventory = { 
         name: $scope.name , 
         email: $scope.email, 
         password: $scope.encryptedData, 
         phoneno:$scope.phoneno 
          }; 
      $.ajax({ 
       url: "https://api.mongolab.com/api/1/databases/geolocation/collections/boom?apiKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
       type: "POST", 
       data: JSON.stringify(inventory), 
       contentType: "application/json; charset=utf-8" 
      }).done(function(msg) { 
       console.log(msg); 
      }); 
}; 
    // populate the code to fill mongo DB 
}); 

回答

1

的修复,我相信(类似于How to pass encrypted data via browser (HTML5) session variable)是添加.toString()到加密的对象。所以,你的加密线改成这样:

$scope.encryptedData = CryptoJS.AES.encrypt($scope.password, "123").toString(); 

而且只是一个提示,而不是alert荷兰国际集团的价值观,console.log会告诉你的实际值是你正在处理的变量)

什么