Retrieving the GET and POST superglobal headers in Javascript is actually very easy, although most of us are spoiled by the method used by PHP ($_GET and $_POST).
Although it takes a few more lines of code, you can mimic PHP.
How To Get $_GET in Javascript
var $_GET = {}; document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () { function decode(s) { return decodeURIComponent(s.split("+").join(" ")); } $_GET[decode(arguments[1])] = decode(arguments[2]); });
You can now access the $_GET variables like so:
alert($_GET['some_variable']);
How To Get $_POST in Javascript
$_POST is handled a little differently (with the help of PHP). This cross-language fix allows you to store the PHP superglobal $_POST into a Javascript variable. You can also use this method for $_GET.
<script> var $_POST = ; document.write($_POST["test"]); </script>
Happy coding!
Thank you very much! It held me alot ^^
Thank you very much, works great
Thank you!
This is working. Thank’s :)))
Thank you! the method for GET is working but the method for POST not… but held me alot!!!
Although POST does but work, It is a good trick for GET!!
By definition, I thiknk POST is no way to retrieve without server side coding as below discussion…
http://stackoverflow.com/questions/10896854/simple-html-post-without-any-server-scripting-can-be-done-using-js
//EDIT (remember to remove spaces between
var $_POST = ;
document.write();
Hi, Thank zou for such an amaying solution. Its working fine.