如何在php变量中存储ajax值?
我想在php变量中存储“选中时”的ajax值如何在php变量中存储ajax值?,php,ajax,jquery,Php,Ajax,Jquery,我想在php变量中存储“选中时”的ajax值 <select name="client_name" onchange="ajaxReq('product_name', this.value);"> <option>- - -</option> <option value="SANY">SANY</option> <option value="MBFC">MBFC</option> <
<select name="client_name" onchange="ajaxReq('product_name', this.value);">
<option>- - -</option>
<option value="SANY">SANY</option>
<option value="MBFC">MBFC</option>
</select>
<span id="slo_product_name"> </span>
<span id="slo_release_no"> </span>
<script type="text/javascript">
var ar_cols = ["client_name","product_name","release_no",null]; var preid = "slo_";
</script>
如何在php变量中存储release_no的ajax值?还有别的办法吗?
function ajaxReq(col, wval) {
removeLists(col);
if(wval!='- - -' && wval!='') {
var request = get_XmlHttp();
var php_file = 'select_list.php';
var data_send = 'col='+col+'&wval='+wval;
request.open("POST", php_file, true);
document.getElementById(preid+col).innerHTML = 'Loadding...';
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(data_send);
request.onreadystatechange = function() {
if (request.readyState==4) {
document.getElementById(preid+col).innerHTML = request.responseText; }
} } }
根据您的代码,您应该在
select\u list.php
脚本中使用此选项:
$col = $_POST['col'];
$wval = $_POST['wval'];
// now you can use those variables to save to DB, or get some data out of DB
我假设您想要级联
元素,您应该更改ajaxReq()
函数:
function ajaxReq(col, wval) {
// first remove all selects that are after this one
var remove = false;
var next = null; // we also need to trap next select so we can fill it
for (i in ar_cols) {
if (ar_cols[i] == col) {
remove = true; // from now on, remove lists
} else if (remove) { // if ok to remove
if (!next) {
next = ar_cols[i]; // now we found next column to fill
}
if (ar_cols[i]) { // remove only non null
removeLists(ar_cols[i]);
}
}
}
if(wval!='- - -' && wval!='' && next) { // also if there is column after to fill
var request = get_XmlHttp();
var php_file = 'select_list.php';
var data_send = 'col='+col+'&wval='+wval+'&next='+next; // also add next param
request.open("POST", php_file, true);
document.getElementById(preid+col).innerHTML = 'Loadding...';
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(data_send);
request.onreadystatechange = function() {
if (request.readyState==4) {
// we fill next select
document.getElementById(preid+next).innerHTML = request.responseText;
}
}
}
}
您的select\u list.php
应该如下所示:
$col = $_POST['col']; // this is just a filter for values in next <select>
$wval = $_POST['wval'];
$next = $_POST['next']; // we need to get this param or we cannot setup next <select>
// using $col and $wval variables get values from DB
echo '<select name="' . $next . '" onchange="ajaxReq(\'' . $next . '\', this.value);">';
foreach ($data as $row) {
echo '<option ...>...</option>'; // fix this to work for you
}
echo '</select>';
$col=$\u POST['col'];//这只是下一步中值的过滤器
$wval=$_POST['wval'];
$next=$_POST['next'];//我们需要获取此参数,否则无法设置下一个参数
//使用$col和$wval变量从数据库中获取值
回声';
foreach($行数据){
echo“…”;//解决这个问题,为您工作
}
回声';
//由于发现错误而更改代码ajax请求应该包含一个以上的参数(
next
列),因为返回的
应该为next准备name和onchange事件,而不是当前更改的。再次检查上面的代码。根据您的代码,您应该在
选择列表中使用它。php
脚本:
$col = $_POST['col'];
$wval = $_POST['wval'];
// now you can use those variables to save to DB, or get some data out of DB
我假设您想要级联
元素,您应该更改ajaxReq()
函数:
function ajaxReq(col, wval) {
// first remove all selects that are after this one
var remove = false;
var next = null; // we also need to trap next select so we can fill it
for (i in ar_cols) {
if (ar_cols[i] == col) {
remove = true; // from now on, remove lists
} else if (remove) { // if ok to remove
if (!next) {
next = ar_cols[i]; // now we found next column to fill
}
if (ar_cols[i]) { // remove only non null
removeLists(ar_cols[i]);
}
}
}
if(wval!='- - -' && wval!='' && next) { // also if there is column after to fill
var request = get_XmlHttp();
var php_file = 'select_list.php';
var data_send = 'col='+col+'&wval='+wval+'&next='+next; // also add next param
request.open("POST", php_file, true);
document.getElementById(preid+col).innerHTML = 'Loadding...';
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(data_send);
request.onreadystatechange = function() {
if (request.readyState==4) {
// we fill next select
document.getElementById(preid+next).innerHTML = request.responseText;
}
}
}
}
您的select\u list.php
应该如下所示:
$col = $_POST['col']; // this is just a filter for values in next <select>
$wval = $_POST['wval'];
$next = $_POST['next']; // we need to get this param or we cannot setup next <select>
// using $col and $wval variables get values from DB
echo '<select name="' . $next . '" onchange="ajaxReq(\'' . $next . '\', this.value);">';
foreach ($data as $row) {
echo '<option ...>...</option>'; // fix this to work for you
}
echo '</select>';
$col=$\u POST['col'];//这只是下一步中值的过滤器
$wval=$_POST['wval'];
$next=$_POST['next'];//我们需要获取此参数,否则无法设置下一个参数
//使用$col和$wval变量从数据库中获取值
回声';
foreach($行数据){
echo“…”;//解决这个问题,为您工作
}
回声';
//由于发现错误而更改代码ajax请求应该包含一个以上的参数(
next
列),因为返回的
应该为next准备name和onchange事件,而不是当前更改的。再次检查上面的代码。您的ajax函数在哪里?我们可以看到
ajaxReq
函数PHP脚本
在服务器端运行并且ajax
在客户端运行PHP变量
,因此您不能将ajax
值分配给PHP变量,是的,您可以在Ajax调用之后操作DOM
。您正在发送'col='+col+'&wval='+wval代码>到您的PHP脚本。索引release\u no
根本没有通过。您的ajax函数在哪里?我们可以看到ajaxReq
函数PHP脚本
在服务器端运行并且ajax
在客户端运行因此您不能将ajax
值分配给PHP变量,是的,您可以在Ajax调用之后操作DOM
。您正在发送'col='+col+'&wval='+wval代码>到您的PHP脚本。索引release\u no
根本没有通过。