Jquery form plugin

Source: Internet
Author: User
Jquery form plugin

Form has two core methods: ajaxform () and ajaxsubmit ()

: Http://malsup.com/jquery/form#download

CodeInstance:

< Script SRC = "Jquery. js" Type = "Text/JavaScript" > </ Script >
< Script SRC = "Jquery. Form. js" Type = "Text/JavaScript" > </ Script >
< Script Type = "Text/JavaScript" >
$ (Document). Ready ( Function (){
$ ( ' # Myform ' ). Ajaxform ( Function (){
$ ( ' Output1 ' Pai.html ( ' Submitted successfully! Come back next time! ' ). Show ();
})
})
// Or
$ ( ' # Myform ' ). Submit ( Function (){
$ ( This ). Ajaxsubmit ( Function (){
$ ( ' # Output1 ' Pai.html ( ' Submitted successfully! Come back next time! ' ). Show ();

});

Return False;//Prevent form submission by default

})

</ Script > < Form ID = "Myform" Action = "Demo. php" Method = "Post" > Name: < Input Type = "Text" Name = "Name" /> < BR /> Address: < Input Type = "Text" Name = "Address" /> < BR /> < Input Type = "Submit" ID = "Test" Value = "Submit" /> < BR /> < Div ID = "Output1" Style = "Display: none ;" > </ Div >

Method Parameters:The parameters of these two methods can be a callback function or an options object.

The callback function is shown in the code.

An options object is defined as follows:

VaR Options = {target: '# output1', // Add the content returned by the server to the element whose ID is output1

Beforsubmit: showrequest, // callback function before submission

Success: showresponse, // callback function after submission

// URL: URL, // It is the form action by default. If declared, it overwrites

// Type: type, // The default value is form's method ('get' or 'post'). If declared

// Datatype: NULL, // 'xml', 'script', or 'json' (accept the type returned by the server .)

// Clearform: True, // after successful submission, clear the values of all form elements.

// Resetform: True, // after successful submission, reset the values of all form elements.

// Timeout: 3000 // request time limit. The request jumps out after 3 seconds .}

 

 

Callback Function showrequest before submission

Function showrequest (Formdata, jqform, options ){

VaR querystring = $. Param (formdata );

Return true ;}

 Formdata: Array object for data submission

 Jqform: A jquery object that encapsulates form elements.

VaR formelement = jqform [0];

VaR address = formelement. Address. value;

In this callback function, as long as no false is returned, the form will be allowedXuSubmission; if false is returned, form submission is blocked. This can be used for form verification before submission.

 

Callback Function showresponse after submission

Function showresponse (responsetext, statustext ){

Alert ('status: '+ statustext +' \ n returns: \ n' + responsetext );

}

Statustext: returns only one status, such as success and error.

Responsetext: contains the data returned by the server.

When XML is returned

 

$ ( ' # Xmlform ' ). Ajaxform ({
Datatype: ' XML ' ,
Success: processxml
});

Function Processxml (responsexml ){
  VaR Name = $ ( ' Name ' , Responsexml). Text ();
  VaR Address = $ ( ' Address ' , Responsexml). Text ();
#( ' # Xmlout ' Pai.html (name +   "   "   + Address );
}

 

 

 

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.