SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Script GET and POST
-
May 4, 2007, 01:58 #1
Script GET and POST
Help neede....
i want to read varaible value using java script.
For ex: url: http://www.test.com/myvar=goon&myvar2=stop
<script>
read myvar_value_here
read myvar2_value_here
</script>
please advice.
thanks
-
May 4, 2007, 03:38 #2
- Join Date
- Apr 2007
- Posts
- 1,205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Everyone repeat after me: "Google is my friend!"
This is one of about a zillion functions for reading GET parameters I found in a Google search:
Code:var qsParm = new Array(); function qs() { var query = window.location.search.substring(1); var parms = query.split('&'); for (var i=0; i<parms.length; i++) { var pos = parms[i].indexOf('='); if (pos > 0) { var key = parms[i].substring(0,pos); var val = parms[i].substring(pos+1); qsParm[key] = val; } } }
Reading POST variables will be a little trickier. You might try using an onsubmit handler in your form to put the POST variables into a cookie. Then use a function on the receiving page to parse the cookie.
-
May 4, 2007, 04:53 #3
Thanks.
i thought there might be some other way out except reading the complete url ...
anyways thanks
-
May 4, 2007, 06:46 #4
- Join Date
- Jan 2007
- Location
- Orlando, FL
- Posts
- 417
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, if you are running php or some other server side script you could do something like this as well:
<?php?
$myvar=$_GET['myvar'];
$myvar2=$_GET['myvar2'];
echo "<script>";
echo "var myvar=$myvar";
echo "var myvar2=$myva2r";
echo "</script>";
?>
This is how I have retrieved post values in the past. The .js function is nodoubt easier though.
-
May 4, 2007, 08:51 #5
- Join Date
- Apr 2007
- Posts
- 813
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
well I used to convert it into JSON format instead of pure echo back, if only you have simple data structure that you can do as above.
Bookmarks