用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));
?>用ajax提交以后数据库中也多了一条 但是显示是null 这是为什么?我ajax用的不对吗?
t.php
立即学习“Java免费学习笔记(深入)”;
免费的开源程序长期以来,为中国的网上交易提供免费开源的网上商店系统一直是我们的初衷和努力奋斗的目标,希望大家一起把MvMmall网上商店系统的免费开源进行到底。2高效的执行效率由资深的开发团队设计,从系统架构,数据库优化,配以通过W3C验证的面页模板,全面提升页面显示速度和提高程序负载能力。3灵活的模板系统MvMmall网店系统程序代码与网页界面分离,灵活的模板方案,完全自定义模板,官方提供免费模
0
<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));
?>
你好像并没有把数据传到后台吧。
哪里传值了?
send里并没有值,有form表单了就没必要写ajax了把 ,配值target="iframe_name"
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号