PHP中的jQuery,使用$ _GET

How can I change a parameter in a PHP file using jQuery? Here is my code, I do not understand why when I click the button the value for $val it doesn't change:

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-1.10.2.min.js">
</script>
</head>

<body>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#test").hide();
    $.get( "jqueryphp.php", { name: "John", time: "2pm" } );
  });
});
</script>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p id="test">This is another paragraph.</p>
<button>Click me</button>
<?php 
if(isset($_GET['time'])) $val=$_GET['time'];
else $val='parametru ne transmis 0';
echo "<br>".$val."</br>"
?>

</body>
</html>

When you load a page in your browser, the browser makes an HTTP request to the server, gets a response and renders it.

When you use Ajax, the browser makes an HTTP request to the server, gets a response, and makes it available to JavaScript.

It does not modify the current page automatically. That page has already been received in the previous response.

You must write JavaScript to use the data it gets in the response (with your current approach, this is done by passing a function as the third argument to $.get to manipulate the DOM of the page.

The problem seems to be here:

if(isset($_GET['time'])) $val0=$_GET['time'];
else $val='parametru ne transmis 0';
echo "<br>".$val."</br>"

What is $val0 versus $val? Shouldn’t it all just be $val? Also, the last line echo makes no sense. There is no ; at the end of the line. And what is this about "<br>".$val."</br>" <br /> is simply a line break. Not an element you have to open & close. Do you want it to have a line break before & after? I am assuming so. Here is my cleanup of that. Should work:

if (array_key_exists('time', $_GET) && !empty(trim($_GET['time']))) {
  $val = $_GET['time'];
}
else {
  $val = 'parametru ne transmis 0';
}
echo '<br />' . $val . '<br />';

I also changed the if(isset($_GET['time'])) to something more robust. Because even if $_GET['time'] is set, it doesn’t mean it has a value.