请高手解决一下 JS和PHP值的问题 有点前后不分了吧!JS是前台跑的,PHP是后台跑的,如果你不提交,这个值怎么会传过去? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是想要这样的效果,就用AJAX。 恩...典型AJAX嘛...一两句话跟你讲不清楚.给你个例子,慢慢看...client.html<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>AJAX结合PHP</title><script language="javascript"> var xmlhttp = false; var currentPos = null; //开始初始化XMLHttpRequest对象 if(window.XMLHttpRequest) { //Mozilla 浏览器 xmlhttp = new XMLHttpRequest(); if (xmlhttp.overrideMimeType) {//设置MIME类别 xmlhttp.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE浏览器 try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } //对象初始化结束 //发送HTTP请求 function sendRequest(url) { if (!xmlhttp) { // 异常,创建对象实例失败 window.alert("不能创建XMLHttpRequest对象实例."); return false; } //确定发送请求的方式和URL以及是否同步执行下段代码 xmlhttp.open("GET", url, true); //指定处理函数 xmlhttp.onreadystatechange = processRequest; //发送请求 xmlhttp.send(null); } //处理返回信息的函数 function processRequest() { if (xmlhttp.readyState == 4) { // 判断对象状态 if (xmlhttp.status == 200) { // 信息已经成功返回,开始处理信息 alert(xmlhttp.responseText); document.getElementById(currentPos).innerHTML = xmlhttp.responseText; } else { //页面不正常 alert("您所请求的页面有异常。"); } } } //显示部门下的岗位 function showPos(obj) { document.getElementById(obj).parentNode.style.display = ""; document.getElementById(obj).innerHTML = "正在读取数据..." currentPos = obj; sendRequest("server.php?playPos="+obj); }</script><link href="css/style.css" rel="stylesheet" type="text/css"></head><body><table width="200" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20"><a href="javascript:void(0)" onClick="showPos('pos_1')">经理室</a></td> </tr> <tr style="display:none"> <td height="20" id="pos_1"> </td> </tr> <tr> <td height="20"><a href="javascript:void(0)" onClick="showPos('pos_2')">开发部</a></td> </tr> <tr style="display:none "> <td id="pos_2" height="20"> </td> </tr> <tr> <td height="20"><a href="javascript:void(0)" onClick="showPos('pos_3')">财务部</a></td> </tr> <tr style="display:none "> <td id="pos_3" height="20"> </td> </tr></table></body></html>server.php<?php/** * 服务器端处理程序,必须使用utf-8编码 *///获得的请求$playPos = $_GET["playPos"];//数组数据$posArray['pos_1'] = array( '总经理', '副总经理');$posArray['pos_2'] = array( '总工程师', '测试工程师', '软件工程师',);$posArray['pos_3'] = array( '财务主任', '会计', '出纳', '审计',);//返回数据if($playPos) { if(is_array($posArray[$playPos])) { foreach($posArray[$playPos] as $pos) { echo "<li>$pos</li>\r\n"; } }}?>PS:你那javascript就别用echo了...呵呵 问题是我想做的联动一级和二级都是从数据库理读出来的啊 我用别人方法可以做 只是想有没有更好的方法啊看来我得好好学学AJAX了 如果是从数据库里读东西出来,还是学一下Ajax吧 用ajax比较方便也可以用php,将js需要的变量(数组)输出 时间紧急啊 用我原来的方法搞定吧 回头狠啃AJAX吧 谢谢各位了 谁有非常详细的在VISTA系统下安装配置Apache+PHP+MySQL+phpMyAdmin的成功方法?网上的不是少这就是缺那 【求助】数组问题 php 找人修改程序 如何获取中间一段字符 PHP如何实现对GZIP(*.gz)文件的解压? 如何从右边向左截取字符串 怎么批量删除文件,超急!!!各为大哥帮帮忙啊 再次求教邮件问题!! 有没有谁用imagemagick做过缩略图? 很简单的但现在就是解决不了?怎么就连不上数据库呢 phpmyadmin导入SVC中文出现乱码?? install安装程序怎么写??
client.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>AJAX结合PHP</title>
<script language="javascript">
var xmlhttp = false;
var currentPos = null;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest)
{
//Mozilla 浏览器
xmlhttp = new XMLHttpRequest();
if (xmlhttp.overrideMimeType) {//设置MIME类别
xmlhttp.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{
// IE浏览器
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
//对象初始化结束 //发送HTTP请求
function sendRequest(url) { if (!xmlhttp) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
} //确定发送请求的方式和URL以及是否同步执行下段代码
xmlhttp.open("GET", url, true); //指定处理函数
xmlhttp.onreadystatechange = processRequest; //发送请求
xmlhttp.send(null);
} //处理返回信息的函数
function processRequest()
{
if (xmlhttp.readyState == 4) { // 判断对象状态
if (xmlhttp.status == 200) { // 信息已经成功返回,开始处理信息
alert(xmlhttp.responseText);
document.getElementById(currentPos).innerHTML = xmlhttp.responseText;
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
} //显示部门下的岗位
function showPos(obj)
{
document.getElementById(obj).parentNode.style.display = "";
document.getElementById(obj).innerHTML = "正在读取数据..."
currentPos = obj;
sendRequest("server.php?playPos="+obj);
}
</script>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head><body>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20"><a href="javascript:void(0)" onClick="showPos('pos_1')">经理室</a></td>
</tr>
<tr style="display:none">
<td height="20" id="pos_1"> </td>
</tr>
<tr>
<td height="20"><a href="javascript:void(0)" onClick="showPos('pos_2')">开发部</a></td>
</tr>
<tr style="display:none ">
<td id="pos_2" height="20"> </td>
</tr>
<tr>
<td height="20"><a href="javascript:void(0)" onClick="showPos('pos_3')">财务部</a></td>
</tr>
<tr style="display:none ">
<td id="pos_3" height="20"> </td>
</tr>
</table>
</body>
</html>server.php
<?php
/**
* 服务器端处理程序,必须使用utf-8编码
*///获得的请求
$playPos = $_GET["playPos"];//数组数据
$posArray['pos_1'] = array(
'总经理',
'副总经理'
);
$posArray['pos_2'] = array(
'总工程师',
'测试工程师',
'软件工程师',
);
$posArray['pos_3'] = array(
'财务主任',
'会计',
'出纳',
'审计',
);//返回数据
if($playPos)
{
if(is_array($posArray[$playPos]))
{
foreach($posArray[$playPos] as $pos)
{
echo "<li>$pos</li>\r\n";
}
}
}
?>PS:你那javascript就别用echo了...呵呵
看来我得好好学学AJAX了