我试图后,我按一个按钮来启动一个PHP脚本的页面,然后重新加载该页面,但我有一个问题,现在我这样做:调用JavaScript代码,按下按钮后,然后刷新
<a href="#" class="btn green big" onclick="startUpdate();">Start Update</a>
那么这是脚本:
<script type="text/javascript">
function startUpdate() {
$.get("Update/startUpdateTxt.php");
return false;
}
</script>
一个txt文件,这些脚本写,所有的作品完美,但我想刷新页面,因为我必须要改变一些元素和阅读我做的TXT文件中的变化,所以我试图这样做:
<script type="text/javascript">
function startUpdate() {
$.get("Update/startUpdateTxt.php");
return window.location.href=window.location.href;
}
</script>
这样
,页面刷新,但phpscript不工作了,并在文件中并没有写任何东西,这是phpscript:
startUpdateTxt.php:
<?php
$myFile = "updateStatus.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "StartUpdate\n";
fwrite($fh, $stringData);
fclose($fh);
?>
我该怎么做才能刷新页面并在后台调用phpscript?
只有完成(成功)AJAX调用 – George 2013-03-19 22:10:43
我需要重新加载页面,我很困惑。如果您无论如何刷新页面,为什么不在服务器端启动您的PHP脚本,然后再绘制页面? – Steve 2013-03-19 22:11:07