ajax传给php的值为空

来源:百度知道 编辑:UC知道 时间:2024/06/06 17:12:56
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中

我记得我开始学ajax的时候也遇见过post接不到值的情况,
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
加上这句看看吧,在open后面加上,回来我再看看我的笔记,呵呵
Good Luck :)