Tag: Man type number this pre parameter Cap blog return
JavaScript APIs are inherently Base64, so we can easily encode and decode them.
var encodedata = Window.btoa ("name=xiaoming&age=10")//code
var decodedata = Window.atob (encodedata)//decoding.
Example:
var encodedData = window.btoa("Hello, world"); // 编码var decodedData = window.atob(encodedData); // 解码
In each browser, the use window.btoa
of encoding a Unicode string triggers an exception with a character that is out of bounds.
Converting the Unicode string to UTF-8 encoding first solves this problem, and the code comes from Johan Sundstr?m:
function Utf8_to_b64 (str) {return Window.btoa (unescape (encodeURIComponent (str))); function B64_to_utf8 (str) {return decodeuricomponent (Escape (Window.atob (str))); Usage:utf8_to_b64 ('? à la mode '); "4pytimogigxhig1vzgu=" B64_to_utf8 (' 4pytimogigxhig1vzgu= '); // "? À la mode "//Translator Note: Within the JS engine, encodeURIComponent (str) is equivalent to escape (unicodeToUTF8 (str))//So the unicodeToUTF8 (str) can be deduced Equivalent to Unescape (encodeURIComponent (str))
//example
$ (function () {
$ (". Edit-btn"). On ("click", Function () {
var policyno=$ (this). Parents (". T-r"). Find (". Policy-no"). Text ();
var holdername=$ (this). Parents (". T-r"). Find (". Holder-name"). Text ();
$.ajax ({
URL: "/reviseservice/revise/reviseoption/" +policyno+ "/" +holdername+ "",
Type: "POST",
Success:function () {
Window.location.href ();
// }
// })
window.open ("/reviseservice/revise/reviseoption/" +policyno+ "/" +holdername+ "");
window.open (encodeURIComponent ("/reviseservice/revise/reviseoption/" +window.btoa (policyNo+ "/" +holderName+ "") ));
window.open ("/reviseservice/revise/reviseoption/" + Window.btoa (unescape (encodeURIComponent (policyNo+ "/" + Holdername+ "")));
})
})
Example
var url= "http://localhost:8080/reviseService/revise/reviseOption/NkRZSUwxNzA1SkswMjAwMTE3MDAwMDA0OS/lvKDlhas="; var uu=url.split ("reviseoption/") [1];console.log (UU);//nkrzsuwxnza1skswmjawmte3mdawmda0os/lvkdlhas=function b64_ To_utf8 (str) {return decodeuricomponent (Escape (Window.atob (str))); var Aa=b64_to_utf8 (UU); Console.log (AA),//6dyil1705jk02001170000049/eight var cc=aa.split ("/"); Console.log (cc);//[" 6dyil1705jk02001170000049 "," Zhang Eight "]
参考文档:http://www.cnblogs.com/fishtreeyu/archive/2011/02/27/1966178.html
https://developer.mozilla.org/zh-CN/docs/Web/API/WindowBase64/btoa
http://www.cnblogs.com/xiao-lei/p/6064134.html
http://www.cnblogs.com/fishtreeyu/archive/2011/02/27/1966178.html
Decoding the encoding in JavaScript