请问如何传送数组变量,这段代码哪里错了?
客户端代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>**论坛</title>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(pare) {
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
//alert(pare);
xmlHttp.open("POST","2.php",true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
xmlHttp.send(pare);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById("show").innerHTML = xmlHttp.responseText;
}
}
}
function add()
{
var a = new Array();
a[0] = 'www';
a[1] = 'jzhpeng';
a[2]='com';
//var a = 'www.jzhpeng.com';
var pare = "topic=" + a;
startRequest(pare)
}
</script>
</head>
<body>
<div id="show"></div>
<input name="button" type="button" value="提交" onClick="add()">
</span></p>
</body>
</html>
服务器端代码:
<?php
$topic=$_POST['topic'];
echo count($topic);
?>
请把修改后的代码写出,谢谢