需求:
实现点击按钮后,数据以表单形式提交至服务器,并接收来自服务器的返回数据。过程中页面不刷新。
html代码
<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; ?>
以上所述是小编给大家介绍的Ajax提交表单并接收json实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对尊托云数网站的支持!
在这篇文章中,我们假定读者了解 VS 基本的调试知识,如: F5 开始使用调试器运...
asp(vb)获取计算机名: %set oWSH = Server.CreateObject("WScript.Network")% %...
? 设置仓库可见性 您可选择能够查看仓库的人员。 本文内容 关于仓库可见性 将仓...
先说一下我的测试环境:XPSP2,IIS5.1,FCKeditor2.0 在IIS上建立一个新的站点,...
【51CTO.com原创稿件】你在使用 MySQL 的 Group by 分组时,是否发现分组后的数...
1. 01.php为主程序,调用smarty模板遍历输出: php include './include/Mysql.cl...
gImageReader 是一个 GUI 工具,用于在 Linux 中利用 Tesseract OCR 引擎从图像...
默认情况下,ASP. NET Core应用会监听一下2个Url: http://localhost:5000 https:...
1.相关基础知识介绍 在Vim中,有四个与编码有关的选项,它们是:fileencodings、...
本文转载自微信公众号「DBA闲思杂想录」,作者潇湘隐者 。转载本文请联系DBA闲思...