Created
April 7, 2013 18:52
-
-
Save ariunbat/5331911 to your computer and use it in GitHub Desktop.
Escape function for AJAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encodeValue(val){ | |
var encodedVal; | |
if(!encodeURIComponent){ | |
encodedVal = escape(val); | |
//Fix the omissions | |
encodedVal = encodedVal.replace(/@/g, '%40'); | |
encodedVal = encodedVal.replace(/\//g, '%2F'); | |
encodedVal = encodedVal.replace(/\+/g, '%2B'); | |
} | |
else{ | |
encodedVal = encodeURIComponent(val); | |
//Fix the omissions | |
encodedVal = encodedVal.replace(/~/g, '%7E'); | |
encodedVal = encodedVal.replace(/!/g, '%21'); | |
encodedVal = encodedVal.replace(/\(/g, '%28'); | |
encodedVal = encodedVal.replace(/\)/g, '%29'); | |
encodedVal = encodedVal.replace(/'/g, '%27'); | |
} | |
//Clean up the spaces and return | |
return encodedVal.replace(/\%20/g, '+'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment