Reputation: 26825
How do I get a particular GET variable in JavaScript or jQuery?
I want to pass it on in ajax script in this sort of way:
$.ajax({
url: 'foo/bar.php',
data: {
search: $(this).val(),
page: something //$_GET['page'] only in js
},
...
Upvotes: 2
Views: 2148
Reputation: 51817
what you try is almost correct, but you dont hav to label the data and you have a wron placed }
in your code.
$.ajax({
url: 'foo/bar.php',
{
search: $(this).val(),
page: 'something'
},
...
});
for more information, take a look at the documentation.
EDIT: to read your get-variable, just do it like you always do: $s = $_GET['search'];
. maybe you have to use $.get
instead of $.ajax
or set the request type for your $.ajax
-call (don't know if it's POST by default, but you should be able to see this using firebug or something similar)
Upvotes: 0
Reputation: 137
Check out http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
Upvotes: 1