PHP中的jQuery,使用$ _GET [英] jQuery in PHP, using $_GET
问题描述
如何使用jQuery更改PHP文件中的参数?这是我的代码,我不明白为什么当我单击按钮时$val
的值不改变:
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>
推荐答案
在浏览器中加载页面时,浏览器向服务器发出HTTP请求,获取响应并呈现.
When you load a page in your browser, the browser makes an HTTP request to the server, gets a response and renders it.
使用Ajax时,浏览器向服务器发出HTTP请求,获得响应,并将其提供给JavaScript.
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.
您必须编写JavaScript才能使用响应中获得的数据(使用当前方法,这是通过将函数作为第三个参数传递给操纵DOM 页面的内容.
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.
这篇关于PHP中的jQuery,使用$ _GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!