ajax传给php的值为空
ajax.jsfunctiontransport2()//删除文章{varb='';vara=document.getElementsByName('item1');fo...
ajax.js
function transport2()//删除文章
{
var b = '';
var a=document.getElementsByName('item1');
for(i=0;i <a.length;i++)
{
if(a[i].checked)
{
var c =a[i].value;
b=b+c+',';
}
}
alert(b);//b能正常输出,比如12,15,
var postStr="del_me="+b;
S_xmlHttpRequest();
xmlHttp.open("POST","delete.php",true);
xmlHttp.setRequestHeader("cache-control","no-cache");
xmlHttp.onreadystatechange=byphp2;
xmlHttp.send(postStr);
}
function byphp2()
{
if(xmlHttp.readyState == 4 {
if(xmlHttp.status == 200)
{
var sousoft=xmlHttp.responseText;
alert(sousoft);
}
}
}
delete.php
<?
header('Content-Type:text/html;charset=GB2312');
echo $_POST[del_me];//这个值始终为空,我想应该为ajax.js中b的值吧
include_once('../Mysql.php');
$del_me=explode(",",$_POST[del_me]); //分割,存入数组
if(count($del_me)>0){
foreach($del_me as $value)
{
$mysql=new Mysql("localhost","root","....","sousoft");
$result1=$mysql->query("delete from book where serial='$value'");
//mysql_free_result($result1);
}
echo"删除成功";
}
$mysql->close_db();
?>
注释说明了 展开
function transport2()//删除文章
{
var b = '';
var a=document.getElementsByName('item1');
for(i=0;i <a.length;i++)
{
if(a[i].checked)
{
var c =a[i].value;
b=b+c+',';
}
}
alert(b);//b能正常输出,比如12,15,
var postStr="del_me="+b;
S_xmlHttpRequest();
xmlHttp.open("POST","delete.php",true);
xmlHttp.setRequestHeader("cache-control","no-cache");
xmlHttp.onreadystatechange=byphp2;
xmlHttp.send(postStr);
}
function byphp2()
{
if(xmlHttp.readyState == 4 {
if(xmlHttp.status == 200)
{
var sousoft=xmlHttp.responseText;
alert(sousoft);
}
}
}
delete.php
<?
header('Content-Type:text/html;charset=GB2312');
echo $_POST[del_me];//这个值始终为空,我想应该为ajax.js中b的值吧
include_once('../Mysql.php');
$del_me=explode(",",$_POST[del_me]); //分割,存入数组
if(count($del_me)>0){
foreach($del_me as $value)
{
$mysql=new Mysql("localhost","root","....","sousoft");
$result1=$mysql->query("delete from book where serial='$value'");
//mysql_free_result($result1);
}
echo"删除成功";
}
$mysql->close_db();
?>
注释说明了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询