I want to send a URL in a POST request in a variable called surl. How should I encode it in JavaScript and decode it in PHP? For example, the value of surl could be http://www.google.co.in/search?q=javascript+urlencode+w3schools.
EDIT
Sorry, I forgot to mention, it’s not form submission but a ajax request.
Use
encodeURIComponent(uri)(for encoding) anddecodeURIComponent(uri)for decoding,E.g (encoding).
Output
Decoding is left for the reader. 🙂
Source: http://www.w3schools.com/jsref/jsref_encodeURIComponent.asp