Sending PHP GET data to server using Html links

前端 未结 2 1070
失恋的感觉
失恋的感觉 2021-01-27 07:51

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

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 08:26

    Put the parameters behind the url:

    index.php?param1=yes¶m2=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¶m2=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;
    }
    

提交回复
热议问题