Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://blogger.hide.vn
- ================
- Several variations of the URL encoding are used today:
- RFC 3986 URI Encoding is defined in RFC 3986 - "Uniform Resource Identifier (URI): Generic Syntax", http://tools.ietf.org/html/rfc3986. See the previous section for details.
- Application/x-www-form-urlencoded Encoding is the same as RFC 3986 URI Encoding except that:
- Space characters ( ) are replaced by plus sign characters (+).
- RFC 1738 URL Encoding is defined in RFC 1738 - "Uniform Resource Locators (URL)", http://tools.ietf.org/html/rfc1738.
- RFC 1738 URL Encoding is the same as RFC 3986 URI Encoding except that:
- Characters outside the URL character set are not required to be converted using UTF-8 schema. Any other schemas can be used to convert characters to byte sequences. Then each byte of the sequence is encoded as %xx, where xx is a pair of hexadecimal digits representing that byte.
- ================
- function URL_ENCODE_RFC_3986(DATA,METHOD){
- var RESULT = "";
- var SUPPORT_METHOD = ["GET","POST"];
- if(typeof(DATA)!="string"){return "REQUIRE DATA IS STRING";}
- if(typeof(METHOD)!="string"){return "REQUIRE METHOD IS STRING";}
- DATA = Trim(DATA.toString());
- METHOD = Trim(METHOD.toString());
- if(DATA=="" || METHOD==""){return "DATA OR METHOD IS MISSING";}
- METHOD = METHOD.toUpperCase();
- if(SUPPORT_METHOD.indexOf(METHOD)==-1){return "METHOD NOT SUPPORT";}
- var vmkreplace = {
- "!": "%21",
- "*": "%2A",
- "'": "%27",
- "(": "%28",
- ")": "%29"
- };
- RESULT = encodeURIComponent(DATA);
- for(var val in vmkreplace){RESULT = RESULT.split(val).join(vmkreplace[val]);}
- if(METHOD=="POST"){RESULT = RESULT.replace(/%20/g,'+');}
- return RESULT;
- }
- function Trim(string){
- if(typeof(string) === "undefined"){return ""}
- return string.toString().replace(/^\s\s*/,'').replace(/\s\s*$/,'');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement