JQuery. Form. js example of jQuery plug-in usage analysis (with demo sample source code), Google map api demo
This document describes the jQuery. Form. js usage of the jQuery plug-in. We will share this with you for your reference. The details are as follows:
I. jQuery. Form. js plug-in implements Ajax submission forms.
Method:
1. formSerilize () is used to serialize the data in the form and automatically organize it into the URL address format suitable for AJAX asynchronous requests.
2. clearForm () clears all input values in the form.
3. restForm resets all fields in the form. Restores all fields in the form to the default value when the page is loaded.
Question: What is the difference between ajaxForm () and ajaxSubmit:
Answer: $ ("# form1"). ajaxForm (); equivalent to the following two rows:
$("#form1".submit)(function(){
$("#form1").ajaxSubmit();
return false;
})
That is to say, ajaxFrom () will automatically block form submission. While ajaxSubmit () does not automatically block form submission. To prevent form submission, you must return false;
Tip 1: If you do not want to jump after the form is submitted, a simple line of code can be implemented, almost the same as not using form submission:
$("#MailForm").ajaxSubmit(function(message) {
Alert ("form submitted successfully!");
};
Note:: Either ajaxForm () or ajaxForm () can have no or accept one parameter. This parameter can be either a callback function or an options object. This object is very powerful and is described as follows:
var options={
URL: URL, / / form address to submit data
Type: type, / / method of form submission (method: post / get)
Target: target, / / the response data returned by the server is displayed in the element (ID) number
Beforesubmit: function(), / / callback function executed before submission
Success: function(), / / callback function to be executed after successful submission
Datatype: null, / / data type returned by server
Clearform: true, / / clear the field values in the form after submitting successfully
Restform: true, / / whether to reset the field values in the form after submitting successfully, that is, to restore to the state when the page is loaded
Timeout: 6000 / / set the request time. After this time, the request will exit automatically, in milliseconds.
}
Example:
Page js Code:
<script src="jQuery.1.8.3.js" type="text/javascript"></script>
<script src="jQuery.Form.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(":submit").click(function () {
var options = {
url: "indexAjax.aspx",
target: "#div2",
success: function () {
alert("ajax请求成功");
}
};
$("#form1").ajaxForm(options);
})
})
</script>
Page HTML code:
<div id="div1">
<form id="form1" method="get" action="#">
<p>My name: < input type = "text" name = "name" value = "please input" / ></p>
<p>My idol is: < input type = "radio" name = "Idol" value = "Andy Lau" / > Andy Lau < input type = "radio" name = "Idol" value = "Jacky Cheung" / > Jacky Cheung</p>
<p>My favorite music type: < input type = "checkbox" name = "musictype" value = "1. Rock" > rock < input type = "checkbox" name = "musictype" value = "2. Easy" > soft < input type = "checkbox" name = "musictype" value = "3. Jazz" > Jazz</p>
<p>< input type = "submit" value = "confirm" / ></p>
</form>
</div>
<div id="div2">
</div>
Background: indexAjax. aspx. cs code
protected void Page_Load(object sender, EventArgs e)
{
string strName = Request["name"];
string strIdol = Request["Idol"];
string strMusicType = Request["musictype"];
Response.Clear();
Response. Write ("my name is:" + strname + "; my idol is:" + stridol + "; my favorite music type:" + strmusictype);
Response.End();
}
Click here to download the sample code.
For more jQuery plug-in usage, refer to related topics on this site.: JQuery common plug-ins and usage summary.
I hope this article will help you with jQuery programming.
Articles you may be interested in:
- Asynchronous Upload Based on jQuery. form. js plug-in
- Submit form forms using ajax using jQuery. form. js plug-in based on jQuery
- Jquery. form. js implements the method of converting form submission to ajax submission.
- Jquery. form. js usage: how to clear form
- Solution to Chinese garbled characters in jquery. form. js of Version 3.01
- Download the month plug-in Attachment source code based on jQuery
- Jquery plug-in jquery. confirm pop-up confirmation message
- JQuery focus chart plug-in SaySlide
- How jQuery defines plug-ins
- Example of form verification implemented by Jquery plug-in easyUi