Sending PHP GET data to server using Html links

Deadly 提交于 2020-01-11 13:24:17

问题


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.


回答1:


Put the parameters behind the url:

index.php?param1=yes&param2=no

Then you can read the variables over $_GET

echo $_GET['param1'];

But this are PHP basics. Perhaps you should read the documentation before.

In jQuery with an ajax request its the same. You can put your parameters behind the url.

$.get('index.php?param1=yes&param2=no', function(data) {
  $('.result').html(data);
  alert('Load was performed.');
});

If you want to read all GET Parameters you can use a foreach loop.

foreach($_GET as $key => $value) {
    echo $key.":".$value;
}



回答2:


The simple ways is,

<a href="page.php?string1=str&string2=str&string3=str"></a>

or a form doing,

<form action="page.php" method="get"></form>


来源:https://stackoverflow.com/questions/11281947/sending-php-get-data-to-server-using-html-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!