var uinfo = {};
var uname = document.getElementById('uname');
var upwd = document.getElementById('upwd');
uinfo['uname'] = uname.value;
uinfo['upwd'] = upwd.value;
var usent = JSON.stringify(uinfo);
var xhr = null;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else{
xhr = ActiveXObject('Microsoft.XMLHttp');
}
xhr.open("POST", "/controler/login.php",true);
//etc
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(usent);
然後php端怎麼接受js發送的資料呢?
$_POST['']
拿不到資料,這部分的格式具體是要指定呢,求大神指導下~~
多謝~!
回複内容:
var uinfo = {};
var uname = document.getElementById('uname');
var upwd = document.getElementById('upwd');
uinfo['uname'] = uname.value;
uinfo['upwd'] = upwd.value;
var usent = JSON.stringify(uinfo);
var xhr = null;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else{
xhr = ActiveXObject('Microsoft.XMLHttp');
}
xhr.open("POST", "/controler/login.php",true);
//etc
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(usent);
然後php端怎麼接受js發送的資料呢?
$_POST['']
拿不到資料,這部分的格式具體是要指定呢,求大神指導下~~
多謝~!
答案太弱了...
xhr.send('json='+usent);
你可以用file_get_contents(‘php://input’);嘗試列印看看是什麼,可以去看看這一篇文章
本文原創釋出php中文網,轉載請注明出處,感謝您的尊重!