Form form plug-in jquery.form.js

Source: Internet
Author: User

Often used to this plug-in, but the old forget how to use, now to everyone write a certain integration.

Using plug-in instances:

General methods of Use

<!--introduce jquery files--<script src="Http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script><script src="Http://malsup.github.com/jquery.form.js"></script><!--Form form--<form id="My_form"action="submit.php"Method="Post"> <p> Name: <input type="text"Name="uname"Id="uname" class="input"></p> <p> Gender: <input type="Radio"Name="Sex"Value="1" checked> Male <input type="Radio"name="Sex"Value="2"> Women </p> <p> Age: <input type="text"Name=" Age"Id=" Age" class="input"style="width:50px"></p> <p style="margin-left:30px"><input type="Submit" class="btn"Value="Submit"> <span id="msg"></span></p> </form> <div id="Output"></div>
  1. $(function() {
  2. var options = {
  3. Beforesubmit: showrequest, //Pre-submission process
  4. Success: showresponse, //processing complete
  5. Resetform: true,
  6. DataType: ' json '
  7. };
  8. $(' #my_form '). Submit(function() {
  9. $(this). Ajaxsubmit(options);
  10. });
  11. });
  12. function showrequest(formData, jqform, options) {
  13. var uname = $("#uname"). Val();
  14. if(uname= ="") {
  15. $("#msg"). HTML("name cannot be empty!") ");
  16. return false;
  17. }
  18. var age = $("#age"). Val();
  19. if(age= ="") {
  20. $("#msg"). HTML("Age cannot be empty!") ");
  21. return false;
  22. }
  23. $("#msg"). HTML("committing ...");
  24. return true;
  25. }
  26. function showresponse(responsetext, statustext) {
  27. $("#msg"). HTML(' submit success ');
  28. var sex = Responsetext.==1? " Male ":" female "
  29. $("#output"). HTML("Name:"+responsetext. uname+"Gender:"+sex+"Age:"+responsetext. Age);
  30. }

Options Configuration

Url The AJAX request will be submitted to the URL, which defaults to the form's Action property value
Type Specifies the method by which the form data is submitted: "GET" or "POST". Default value: The Method property value of the form (if no default is found for "GET").
DataType The type of data expected to be returned. NULL, "XML", "script", or "JSON" one of them. DataType provides a method that specifies how the server's response is handled. This is directly reflected in the Jquery.httpdata method. The following values are supported:
' XML ': if datatype = = ' xml ', the server response will be treated as XML. Also, if the "success" callback method is specified, the Responsexml value is returned.
' JSON ': if datatype = = ' json ', the server response will be evaluated and passed to the ' success ' callback method if it is specified.
' Script ': if datatype = = ' script ', the server response will be evaluated as plain text.
Default value: null (server returns RESPONSETEXT value)
Target Indicates the element in the page that is updated by the server response. The value of the element may be specified as a jquery selector string, a jquery object, or a DOM element.
Default value: null.
Beforesubmit The callback function that was called before the form was submitted. The "Beforesubmit" callback function is provided as a hook to run the pre-commit logic or to validate the form data. If the "Beforesubmit" callback function returns false, the form will not be committed. The "Beforesubmit" callback function has three invocation parameters: form data in array form, jquery form objects, and options objects in the incoming ajaxform/ajaxsubmit.
Default value: null
Success callback function that is called after the form has been successfully committed. If the "Success" callback function is provided, it is called when the response is returned from the server. The datatype option value is then determined to return the value of ResponseText or Responsexml.
Default value: null
ClearForm Indicates whether the form data is purged if the form submission succeeds. Default value: null
Resetform Indicates whether the form submission succeeds if it is reset. Default value: null

Related Article

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.