用ajax提交以后数据库中也多了一条 但是显示是null 这是为什么?我ajax用的不对吗?
t.php
function ajax(url,funsucc){
var oAjax=new XMLHttpRequest();
oAjax.open('POST',url,true);
oAjax.send();
oAjax.onreadystatechange=function(){
if(oAjax.readyState==4){
if(oAjax.status==200){
funsucc(oAjax.responseText);
}
}
}
}
window.οnlοad=function(){
var oTxt=document.getElementById('txt1');
var oBtn=document.getElementById('btn1');
oBtn.οnclick=function(){
ajax("ajax.php",function(){
window.location.reload();
});
}
}
提交
ajax.php
$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
$txt=$_POST["txt"];
$stmt=$pdo->prepare("insert into ajax(txt)values(?)");
$stmt->execute(array($txt));
?>