php使用str_replace替换多维数组的实现方法分析

2017-07-07 来源:互联网

实现点击按钮后,数据以表单形式提交至服务器,并接收来自服务器的返回数据。过程中页面不刷新。

<html xmlns="http://www.w3.org/1999/xhtml">  

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  

<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>  

<script src="./testajaxjs.js"></script>  

<head>  

</head>  

<body>   

<form id="form1">    

<p>xingming:<input type="text" name="xingming"/></p>    

<p>nianling:<input type="text" name="nianling"/></p>   

</form>   

<button type="button" id="mybt" onclick="mysubmmit()">    

ajax提交   

</button>  

</body> 

</html> 

js代码

function mysubmmit(){  

$.ajax({   type: "POST",   

url: "testajaxend.php",   

data: $('#form1').serialize(),   

async: false,   

success: function(databack){   

 //console.log("chenggong");    

console.log(databack);   },  

 error: function(request){   

 console.log("shibaile");  

 }  }); 

后端php代码

<?php   

$name = $_POST['xingming'];   

$age = $_POST['nianling'];  

 $myarray = 

array("name"=>$name, "age"=>$age);  

 $myjson = json_encode($myarray);  

 echo $myjson; 

?> 


本文关键词:

本文均为荣益互联摘自权威资料,书籍,文章,或来自网络,如有版权纠纷或违规问题,请联系我们删除。我们欢迎您的分享,谢绝直接抄袭复制。感谢…

关注格度视觉