前端:
<script> $.fn.serializeObject=function() { varo={}; vara=this.serializeArray(); $.each(a,function(){ if(o[this.name]){ if(!o[this.name].push){ o[this.name]=[o[this.name]]; } o[this.name].push(this.value||''); }else{ o[this.name]=this.value||''; } }); returno; }; document.getElementById("hand").onclick=function(){ varrequest=newXMLHttpRequest(); request.open("POST","../controller/post.PHP"); varjsonuserinfo=$('#form1').serializeObject(); vardata=JSON.stringify(jsonuserinfo); request.setRequestHeader("Content-type","application/x-www-form-urlencoded"); request.send(data); request.onreadystatechange=function(){ if(request.readyState===4){ if(request.status===200){ document.getElementById("postResult").innerHTML=request.responseText; }else{ alert("发生错误:"+request.status); } } } } </script>
后台:
<?PHP error_reporting(0); require_once('../model/PdoMysqL.class.PHP'); require_once('../model/config.PHP'); header("Content-Type:text/html;charset=utf-8"); if($_SERVER["REQUEST_METHOD"]=="POST"){ create(); } //创建笼位申请信息 functioncreate(){ //判断信息是否填写完全 $data=file_get_contents("PHP://input"); ... //忽略后面代码原文链接:/ajax/163110.html