Html5 own verification forms and solutions (with examples) filed with ajax

With submit to submit the form, then js listening submit method, submit the form with ajax submit the final stop automatically submitted.  

In the standard browser, the browser's default behavior to prevent the use of event.preventDefault (), and in IE6 ~ 8, use the returnValue property to achieve.

<html>
<head>
    <script type="text/javascript" src="jquery-1.9.0.min.js"></script>
</head>
<body>
    <form action="" id='submitform'>
        username: <br>
        <input type="text" name="username" value="" required="required"> <br>
        password: <br>
        <input type="text" name="password" value="" required="required"> <br><br>
        <input type="submit" value="Submit">
    </form>
    <script type="text/javascript" language="javascript">
        $("#submitform").on("submit", function(event) {
            $.ajax({
                ...... 
            }); 
            // prevent form submission submit 
            the event.preventDefault ();
             // or to false return 
            // return to false; 
        });
     </ Script > 
</ body > 
</ HTML >

 

 

 

Guess you like

Origin www.cnblogs.com/niuben/p/11431482.html