**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文件中顯示並將它們存儲在數據庫中。如何從JavaScript獲取數組值並在php中顯示相同的值
縮進你的代碼,會更容易爲人們看看未來 - http://beta.phpformatter.com/ – Edward
編碼您在JSON JavaScript數組。然後在你的PHP中使用'json_decode()'。簡單。 – Jimbo
接受我的修改和虐待:) – Edward