使用HTML链接将PHP GET数据发送到服务器
我有一段时间没有写PHP GET请求了。所以我有点生锈。但是,如何使用HTML链接发送GET数据。如果我使用jQuery的get方法,我知道该怎么做,但是我只是想知道在HTML中使用href或其他类似方法是否更简单。
I haven't wrote PHP GET requests in a while. So I'm a little rusty. But how do I send GET data using an Html link. If I use jQuery's get method's I know how to do it, but I was just wondering if there is a simpler way using the href in Html or something similar.
将参数放在网址后面:
index.php?param1=yes¶m2=no
然后,您可以在 $ _ GET
echo $_GET['param1'];
但这是PHP的基础知识。也许您应该先阅读文档。
But this are PHP basics. Perhaps you should read the documentation before.
在jQuery中使用ajax请求相同。您可以将参数放在网址后面。
In jQuery with an ajax request its the same. You can put your parameters behind the url.
$.get('index.php?param1=yes¶m2=no', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
如果要读取所有GET参数,可以使用foreach循环。
If you want to read all GET Parameters you can use a foreach loop.
foreach($_GET as $key => $value) {
echo $key.":".$value;
}