开发者

How do I read a GET variable from JavaScript/jQuery?

开发者 https://www.devze.com 2023-01-22 14:37 出处:网络
How do I get a particular GET variable in JavaScript or jQuery? I want to pass it on in ajax script in this so开发者_运维百科rt of way:

How do I get a particular GET variable in JavaScript or jQuery?

I want to pass it on in ajax script in this so开发者_运维百科rt of way:

$.ajax({
    url: 'foo/bar.php',
    data: { 
       search: $(this).val(),
       page: something //$_GET['page'] only in js
    },
    ...


Check out http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消