简体   繁体   中英

How to use `GET` parameters in a HTML document?

I have a HTML document and I want to send a parameter.

Let's name the document Categoty , and all it do it sends a request to the server (via Ajax) to get something on this categoty.

Suppose I'm using PHP, I would simply send the parameter:

localhost/Categoty.php?cat=somecat ,

and read it in the PHP document: $_GET['cat'] .

My question is if there's something similar in HTML (or Javascript)?

I though about hashtag (.ie categoty.html#somecat ) , but I'm using jQuery mobile in my Android Hybrid application so it makes some issues.

Thanks in advance.

use the jQuery URL Parser in this link and then try:

jQuery.url().param('cat');

you can also access all other info we usually need in terms of dealing with GET parameters, like:

jQuery.url().attr('protocol');

returns the URL protocol like: http or https

jQuery.url().attr('host')

returns the host like stackoverflow.com

you can also get the segments of your URL like this:

jQuery.url().segment(1);//for instance in this very page's url it returns "posts"

at the end:

jQuery.url().param('cat') in javascript does the same as $_GET['cat'] does in PHP

jQuery ajax can do it , use $.ajax();

$.ajax({
    type: 'GET',
    url: 'http://localhost/Categoty.php?cat=somecat',
    success: function(responseTxt,statusTxt,xhr){
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM