ajax 获取接口返回值

code

$.ajax({
      type: "POST",
      url: "/encrype",
      contentType: "application/json",
      data: JSON.stringify(json), /*传给后端的数据格式json*/
      dataType: "json", /*后端返回的数据格式json*/
      success: function(data){
          res=data.encryped;
          console.log("c-------> server返回加密后的字符串------>",res);
          var decrypt = new JSEncrypt();
          decrypt.setPrivateKey($('#privkey').val());
          var uncrypted = decrypt.decrypt(res);
          console.log("d-------> js解密c后的字符串------>",uncrypted);
          // Now a simple check to see if the round-trip worked.
          if (uncrypted == $('#input').val()) {
          }
          else {
            alert('Something went wrong....');
          }
      },
      error: function (message) {
          console.log("error");
      }
    });

原文地址:https://www.cnblogs.com/sea-stream/p/14182100.html