javascript - 为什么数据库中显示的是null呢?
本文介绍了javascript - 为什么数据库中显示的是null呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
用ajax提交以后数据库中也多了一条 但是显示是null 这是为什么?我ajax用的不对吗?
t.php
<script type="text/javascript">
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);
}
}
}
}
</script>
<script type="text/javascript">
window.onload=function(){
var oTxt=document.getElementById('txt1');
var oBtn=document.getElementById('btn1');
oBtn.onclick=function(){
ajax("ajax.php",function(){
window.location.reload();
});
}
}
</script>
<form method="post">
<input type="text" id="txt1" name="txt">
<button id="btn1" type="submit">提交</button>
</form>
ajax.php
<?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));
?>
解决方案
你好像并没有把数据传到后台吧。
这篇关于javascript - 为什么数据库中显示的是null呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文