Javascript 网页更新不刷新不工作
我正在尝试在不刷新页面的情况下进行页面更新,我已经阅读了一些教程,并提出了以下代码。然而,它似乎不起作用。当你按下按钮时,似乎什么也没发生 Index.php代码Javascript 网页更新不刷新不工作,javascript,jquery,ajax,refresh,partial-page-refresh,Javascript,Jquery,Ajax,Refresh,Partial Page Refresh,我正在尝试在不刷新页面的情况下进行页面更新,我已经阅读了一些教程,并提出了以下代码。然而,它似乎不起作用。当你按下按钮时,似乎什么也没发生 Index.php代码 <!DOCTYPE html> <html> <head> <script type="text/javascript" src="jquery.js"></script> <script>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script>
function updateShouts()
{
$('#refresh').load('update.php');
alert('it works!'); uncomment this to know if your script works
}
</script>
</head>
<body>
<div id="refresh">
<?php
include('update.php');
?>
<button onclick="updateShouts()">Try it</button>
</div>
</body>
</html>
函数updateShouts()
{
$('#refresh').load('update.php');
警报('it works!');取消对此的注释以了解脚本是否有效
}
试试看
update.php代码
<?php
print strftime('%c');
?>
您必须将jquery链接与其他脚本分开声明
<script type="text/javascript" src="jquery.js"></script>
<script>
function updateShouts()
{
$('#refresh').load('update.php');
//alert('it works!'); uncomment this to know if your script works
}
</script>
函数updateShouts()
{
$('#refresh').load('update.php');
//警报('it works!');取消对此的注释以了解脚本是否有效
}
或者您可以使用更新的在线jquery库
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
function updateShouts()
{
$('#refresh').load('update.php');
//alert('it works!'); uncomment this to know if your script works
}
</script>
函数updateShouts()
{
$('#refresh').load('update.php');
//警报('it works!');取消对此的注释以了解脚本是否有效
}
我不完全确定IoQ是什么意思?请注意您的脚本标题?只需删除src并像上面的例子那样分离它。只是尝试了一下,它仍然不起作用。我取消了警报弹出窗口的注释,它没有显示提示它没有启动。已更新问题以显示新代码由于语法错误,此问题不起作用。。同时删除文本“取消对此的注释以了解脚本是否工作”,或者用src=''替换jquery链接