[英]I am using Jquery to load dynamic php data into my file but cannot store the data into Javascript variables
[英]Store data on my XML file while redirecting it to my home page using PHP and Javascript
我創建了一個PHP頁面,該頁面中有一種表單會將數據存儲在XML文件中。
我已經寫了可以存儲數據的PHP代碼,但是現在我也必須將其重定向到我的主頁。 但是主要的錯誤是當我編寫用於重定向頁面的Javascript代碼時,則沒有存儲數據。
現在,我目前已經在PHP代碼本身中編寫了Javascript代碼。
我將在下面為我的頁面提供代碼。
<html>
<head>
<title>Login</title>
</head>
<body bgcolor="#f0f0f0">
<?php
if(isset($_REQUEST['ok']))
{
$xml = new DOMDocument("1.0","UTF-8");
$xml->load("a.xml");
$rootTag = $xml->getElementsByTagName("document")->item(0);
$dataTag = $xml->createElement("data");
$aTag=$xml->createElement("a",$_REQUEST['a']);
$bTag=$xml->createElement("b",$_REQUEST['b']);
$dataTag->appendChild($aTag);
$dataTag->appendChild($bTag);
$rootTag->appendChild($dataTag);
$xml->save("a.xml");
}
echo "<script type=\"text/javascript\">
function Home()
{
window.location.href=\"navbar.php\";
}
</script>
"
?>
<form action="index.php" method="post">
<table cellspacing="20px" style="margin-left:500px;" id="atable">
<tr>
<td>User Name </td>
<td> <input type="text" name="a" width="75" /> </td> <!--Inserting textbox in the page with justified width-->
</tr>
<tr>
<td> Password </td>
<td> <input type="password" name="b" width="75" /> </td> <!--Inserting textbox in the page with justified width-->
</tr>
<tr>
<td>
<input type="button" name="ok" value="Login" onclick="Home()" />
</td>
</tr>
</table>
</form>
</body>
</html>
嘗試這個。 您需要使用header("Location:navbar.php");
<?php
if(isset($_REQUEST['ok'])){
$xml = new DOMDocument("1.0","UTF-8");
$xml->load("a.xml");
$rootTag = $xml->getElementsByTagName("document")->item(0);
$dataTag = $xml->createElement("data");
$aTag=$xml->createElement("a",$_REQUEST['a']);
$bTag=$xml->createElement("b",$_REQUEST['b']);
$dataTag->appendChild($aTag);
$dataTag->appendChild($bTag);
$rootTag->appendChild($dataTag);
$xml->save("a.xml");
header("Location:navbar.php");
exit;
}
?>
<html>
<head>
<title>Login</title>
</head>
<body bgcolor="#f0f0f0">
<form action="index.php" method="post">
<table cellspacing="20px" style="margin-left:500px;" id="atable">
<tr>
<td>
User Name </td>
<td> <input type="text" name="a" width="75" /> </td> <!--Inserting textbox in the page with justified width-->
</tr>
<tr>
<td> Password </td>
<td> <input type="password" name="b" width="75" /> </td> <!--Inserting textbox in the page with justified width-->
</tr>
<tr>
<td>
<input type="submit" name="ok" value="Login" />
</td>
</tr>
</table>
</form>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.