**Main.php file**
<html>
<head>
<script>
function showUser(str) {
if(str =="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
var internal = new Array();
var external = new Array();
var sub = new Array();
var end = document.getElementById("tot").value;
for (var i=0; i<end; i++) {
sub[i] = document.getElementById("sub["+ i +"]").innerHTML;
internal[i] = document.getElementById("inte["+ i + "]").value;
external[i] =document.getElementById("exte["+ i +"]").value;
xmlhttp.open("GET","getsub.php?
q="+sub[i]+"&in="+internal[i]+"&ex="+external[i]+"&ed="+end,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<?php
echo "<td> <input type='text' name='internal' id = 'inte[$i]' onkeypress='mykey()' width='30'/> </td>";
echo "<td> <input type='text' name='external' id = 'exte[$i]' width='30'/> </td>";
?>
<div id = "txtHint"></div>
</body>
</html>
**The php file** getsub.php
<?php
if (isset($_GET['q[]'])
AND isset($_GET['in[]'])
AND isset($_GET['ex[]'])
AND isset($_GET['ed'])) {
$host='localhost';
$user='test1';
$pass='test1';
$db='test1';
$con = mysql_connect($host,$user,$pass);
mysql_select_db($db);
$i=0;
echo $ed = $_GET['ed'];
$q[] = array();
$m[] = array();
$y[] = array();
for($i=0; $i<=$ed; $i++) {
echo $q[$i] = $_GET['q[$i]'];
echo $m[$i] = $_GET['in[$i]'];
echo $y[$i] = $_GET['ex[$i]'];
}
}
?>
我想显示从 Javascript 传递到 PHP 文件的记录。例如,我想将每个包含 5 个值的变量从 Javascript 传递到 PHP 文件。相同的 5 个值,我想在 PHP 文件中显示并将它们存储在数据库中。