我有一个奇怪的问题,我无法获得一个php网页刷新,这是由下拉触发的。以下是主文件(SelectForceRefresh.php):
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1" /><!-- Optimistically rendering in Chrome Frame in IE. -->
<title>My form</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<script>
function ConfigFileSelection(id)
{
$.ajax({
type: "GET",
url: "RefreshConfig.php",
data: "confFile = " + id,
success: function GotHere()
{
alert("Got here!");
}
});
}
</script>
<select name="userconfigoption" onchange="ConfigFileSelection(this.value);" >
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</body>
</html>下面是“链接”文件(RefreshConfig.php):
<?php
if(isset($_GET['confFile'])){
CopyUserConfig($_GET['confFile']);
}
function CopyUserConfig($id)
{
header("Location: SelectForceRefresh.php");
exit;
}
?>问题是,当我从下拉菜单中选择时,会触发javascript函数,因为我看到警报"Got!“,但是其他php文件从未被触发以进行刷新。我已经做了三天了,不知道我错过了什么。我已经回顾了这里关于堆栈溢出的其他解决方案,比如:
on Change of dropdown list showld call the php function
我试着从那里学到这种技术,但它们根本不起作用。
我在这里错过了什么?两个文件位于同一个目录中。提前谢谢。
发布于 2013-08-11 17:10:05
您不能让您使用AJAX函数针对的PHP文件刷新您的网页。最好的方法是在AJAX的成功函数中执行if (JavaScript也是如此)。类似于:
$.ajax({
type: "GET",
url: "RefreshConfig.php",
data: "confFile = " + id,
success: function GotHere() {
window.location.reload();
}
});https://stackoverflow.com/questions/18174352
复制相似问题