Mvc+jquery Development B/s System (iii) Form submission

Source: Internet
Author: User
Tags json

Speaking of form submission, is no one knows, nobody does Xiao Wow. Today we'll talk about how to use JQUERY+MVC to process the submission of forms.

The effect you want to achieve:

1, before submitting the form verification

2. Form Verification

3, after the submission of feedback information

OK, let's talk about the principle of the work first.

The front desk <form action= ' xxx.aspx ' method= ' post ' ></form>,action specifies the processing page that accepts the form. Method Here we only say post

If you submit a form with Ajax, the natural xxx.aspx is the URL of the request. The callback of the AJAX request is the response to the form's submission (error, success), and the feedback we submit is expressed in a floating layer (lightbox). Not to use alert (""); This is a very awkward clang.

We introduce a jquery plugin http://www.malsup.com/jquery/form/#api This is a slightly famous plugin that is easy to use.

For its use, you can search for the next.

So what we need to do is

1, the use of jquery.form.js

2, the realization of Lightbox

3. How to verify

Code

Registering the form's Ajaxform this method requires calling the Jquery.ajaxwindow.js method
There is an action in the general form, so the parameter may only need to pass a callback,
If a form has multiple submit buttons, you need to submit a different URL
This method is used to register form submission, if there are multiple submit buttons, it is best to register a default, otherwise the validation method does not work
$.fn.submitform = function (args) {
var URL, id, callback, before;
id = this.attr ("id");

if (typeof (args) = = "string") {//Only one URL is passed
url = args;
before = undefined;
callback = undefined;
}
else {
args = args | | New Object ();
url = Args.url | | This.attr ("action");
if (typeof (args) = = "function") {//Only one callback
callback = args;
}
else {
before = Args.before;
callback = Args.callback;
}
}
Input validation
This.inputvalidate ()//This is an "input-time validation" that we need to implement.
This.ajaxform ({//) call the Jquery.form.js form registration method here.
Url:url,
Beforesubmit:function (A, F, O) {//Pre-submission processing
Submit Validation
if ($ ("#" + ID). submitvalidate () = = false)//Here we need to implement the "Commit time validation".
return false;
if (before!= undefined && before () = = False) {
return false;
}
O.datatype = "json";//Specifies that the returned data is in JSON format.
},

Success:function (data) {//post-submission feedback processing
if (data = = "" | | data = = NULL) {
return false;
}
var msg = new ajaxmsg (data);//This ajaxmsg is what we need to achieve Lightbox
Msg.show (callback);//show The result of this feedback.
return false;
}
});
return this;
}

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.