1. ajaxform
Purpose:
(1) pre-load JS events to form
(2) Submit the JS verification form before the action
(3) After submitting the action, the result will be processed by JS and will not be automatically redirected.
Requirements:
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script><script type="text/javascript" src="js/jquery.form.js"></script>
Example:
<SCRIPT type = "text/JavaScript"> // var error = document. getelementbyid ('errordiv '); // note that VaR error is declared only here. Do not assign values. The value assignment is also null var error; // wait for the Dom to be loaded $ (document ). ready (function () {error = document. getelementbyid ('errordiv '); // bind 'myform' and provide a simple callback function var Options = {// target:' # output1 ', // target element (s) to be updated with server response beforesubmit: validate, // pre-submit callback datatype: 'json', // 'xml', 'script ', or 'json' (expected server response type) // datatype must be placed before callback (JSON), because callback (JSON) needs to call the JSON variable success: function (JSON) {JSON = eval (JSON); If (JSON. errcode = 0) {window. location. href = 'seller/seller. JSP ';} else {error. innerhtml = "incorrect account and password. Please log on again. ";}}// post-submit callback // other available options: // URL: URL // override for form's 'action' attribute/type: type // 'get' or 'post', override for form's 'method' attribute // clearform: True // clear all form fields after successful submit // resetform: true // reset the form after successful submit // $. ajax options can be used here too, for example: // Timeout: 3000}; $ ('# loginform '). ajaxform (options) ;}); function validate () {var username = document. getelementbyid ("name "). value; var Password = document. getelementbyid ("PWD "). value; // if it is null, it can be handed over to the foreground for processing; If (username. length = 0) {error. innerhtml = "account cannot be blank"; return false;} else if (password. length = 0) {error. innerhtml = "the password cannot be blank"; return false;} error. innerhtml = "logging on" ;}</SCRIPT>
Done
Submit a form using Ajax