Ajax form submission No refresh

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Login Angularjs</title>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "Width=device-width, Initial-scale=1,maximum-scale=1,user-scalable=no" >
<link rel= "stylesheet" href= "Css/bootstrap.min.css" >
<link rel= "stylesheet" href= "Css/login.css"/>
<script type= "Text/javascript" src= "Js/jquery-1.8.1.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {//dom
$ ("#button"). Click (function () {///When the button is clicked the handler function
PostData (); Execute PostData function when button is clicked
});
});
function PostData () {//Submit data functions
$.ajax ({//Invoke jquery's Ajax method
Type: "POST",//Set the form of Ajax method submission data
URL: "ajax_output.php",//Submit data to ok.php
Data: "Username=" +$ ("#username"). Val () + "&pass= "+$" ("#pass"). Val () + "&age= "+$" ("#age"). Val (),//input box Username pass age multiple values& SymbolsThe value in the file as the submitted data
Success:function (msg) {//Post successful callback, MSG variable is the content of the ok.php output.
Alert ("Data submitted successfully"); If necessary, you can display the value of the MSG variable in a DIV element
}
});
}


</script>
<body>
<div class= "Container" >
<div class= "img-responsive" id= "MSG" ></div>
<form class= "Form-signin" id= "Form1" method= "Post" name= "User_info" action= "" >
<input name= "username" id= "username" type= "text" value= ""/>
<input name= "Pass" id= "pass" type= "text" value= ""/>
<input name= "Age" id= "age" type= "text" value= ""/>
<input type= "Submit" name= "button" id= "button" value= "Submit"/>
</form>
</div>
</body>



<?php
    header ("Content-type:text/html;charset=utf-8");
/* $mysql _username= "localhost"; Connect database user name
    $mysql _password= "";//Connect Database Password */
    $mysql _database= "test"; Database name
    
   //Connect to database
   $conn = mysql_connect (' localhost ', ' Root ', ') or Die ("Mysql_connect:". Mysql_errno ());
    mysql_select_db ($mysql _database);
    $username =$_post[' username '];
    $pass =$_post[' pass ');
    $age =$_post[' age '];
    $sql = "INSERT into ' login2 ' VALUES (' $username ', ' $pass ', ' $age ')";
    $query = mysql_query ($sql);
   if ($query) {
        echo ' 1 ';
   }else{
        echo ' registration failed! ';
       }

;

Ajax form submission No refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.