如何解决“将循环结构转换为JSON”错误?

时间:2016-10-28 16:33:08

标签: javascript json ajax

我想将加密的密码保存到数据库,但我得到“将循环结构转换为JSON”错误。我的功能如下:

function changeit(id,rppass){

             $.ajax({
                     type: "PUT",
                     data: JSON.stringify({Password:rppass}),
                     url: "http://localhost:55288/API.svc/EC/"  + id,
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     processdata: true, 
                     success: function(r) {
                         if (r==true){
                           alert("Your password was changed");
                                      activate_page("#Ads");   
                            } else {
                              alert("Oops! an error occurred and your password was not changed."); return false;
                                   }



                                    },
                                });  
        }

根据我从其他帖子获得的信息,我在ajax调用之前放了这段代码:

var cache = [];
          var newpass = JSON.stringify(rppass, function(key, value) {
                if (typeof value === 'object' && value !== null) {
                if (cache.indexOf(value) !== -1) {
                    // Circular reference found, discard key
                    return;
                }
                    // Store value in our collection
                    cache.push(value);
                }
                    return value;
                        });
            cache = null; // Enable garbage collection

这里newpass将aes.js中的部分加密代码作为值,而不是加密密码。

保存此密码的最佳方式是什么?

0 个答案:

没有答案