[英]PHP AJAX POST send multiple variables
用ajax发布到php我可以发送多个变量,如果是这样,那么语法是什么?
loadXMLDoc("scripts/product_transfer.php?group="+group+"subgroup="+subgroup+"user="+user+,function()
这样的事情?
这是功能代码:
//--------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------
//Function to handle ajax
function loadXMLDoc(url,cfunc)
{
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=cfunc;
xmlhttp.open("POST",url,true);
xmlhttp.send();
}
是的,你可以,但你忘记了&
价值观之间。 您也可以使用POST方法将数据作为参数send()
到send()
方法。 另外不要忘记在字符串值上使用encodeURIComponent()
:
xmlhttp.open( "POST", url, true );
xmlhttp.send( "group="+encodeURIComponent(group)+
"&subgroup="+encodeURIComponent(subgroup)+
"&user="+encodeURIComponent(user) );
我已为此编写代码及其工作良好,
页面-1。
<select name="qt_n1" id="qt_n1" style="width: 100px;" onchange="return q1mrks(this.value,<?php echo $gen1_marks; ?>)">
<option>No. of Que.</option>
<?php
for($i=1;$i<=25;$i++){?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php } ?>
</select>
页面2.js
function q1mrks(country,m)
{
// alert("hellow");
if (country.length==0)
{
//alert("hellow");
document.getElementById("q1mrks").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("q1mrks").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../location/cal_marks.php?q1mrks="+country+"&marks="+m,true);
//mygetrequest.open("GET", "basicform.php?name="+namevalue+"&age="+agevalue, true)
xmlhttp.send();
}
而我只是在第三页上得到了值
页面3.php
<?php
echo $Q1mrks = $_GET['q1mrks'];
echo $marks = $_GET['marks'];
?>
<div id="q1mrks"></div>
谢谢,
你应该添加&或'&amp; 在查询字符串中的不同变量之间
脚本/ product_transfer.php?组= “+组+” &亚组= “+亚组+” &用户=“+用户
尝试这个!
loadXMLDoc("scripts/product_transfer.php?group="+group+"&subgroup="+subgroup+"&user="+user+, function() { //Code to run when data is sent back});
data="postvarname1="+varvalue+"postvarname2"+var
等等......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.