Ajax submits a form and receives the json instance code. The ajax form is a json instance.
Requirements:
After clicking the button, the data is submitted to the server in a form and the returned data from the server is received. The page is not refreshed during the process.
Html code
<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>
Js Code
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"); } });}
Backend php code
<?php $name = $_POST['xingming']; $age = $_POST['nianling']; $myarray = array("name"=>$name, "age"=>$age); $myjson = json_encode($myarray); echo $myjson;?>
The above section describes how to submit a form using Ajax and receive the json instance code. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!