How to verify Ajax submission form parameters with jQuery

php中世界最好的语言
Release: 2018-03-31 11:04:16
Original
1328 people have browsed it

This time I will show you how jQuery verifies the parameters passed in the Ajax submission form. What are theprecautionsfor jQuery to verify the parameters passed in the Ajax submission form. The following is a practical case, let's take a look. The

serialize() method creates a URL-encoded textstringby serializing the form value. Instead of passing parameters one by one

The ajax parameter passing method written in the past

$.ajax({ url : "${ctx}/SJStandardDamPartition/insertOrUpdateDamPartition", type : "post", dataType : "json", data: {beginsectionid:function(){ return $('#number option:selected').val(); }, beginelevation:function(){ return $('#onset').val(); }, endelevation:function(){ return $('#end').val(); } }, success : function(result) { } });
Copy after login

uses the parameter passing method of serialize() When doing business, you may encounter situations where you need multiple

forms

on the same page, but you don’t want the page to refresh or jump after submitting a form. Then what we consider is Ajax submission of the form, so how to make it Can jQuery'svalidatorplug-in also validate asynchronously submitted forms? Let's continue reading.Here, I will use an example from the Internet to illustrate.

The following is a more common jquery .ajax submission form

var param = $("#standForm").serialize(); $.ajax({ url : "${ctx}/SJStandardStandardInfo/insertOrUpdateStandardInfo", type : "post", dataType : "json", data: param, success : function(result) { } });
Copy after login
If you want to use ajax to submit the form, you also want to use jquery If validate is used for verification, it can be solved like this: the form is still the normally written form content, and the type is still the submit type, but in the validate method after passing the verification, ajax is used to submit the form

$("#submitButton").click(function(){ //序列化表单 var param = $("#leaveSave").serialize(); $.ajax({ url : "leaveSave.action", type : "post", dataType : "json", data: param, success : function(result) { if(result=='success') { location.href='allRequisitionList.action'; } else if(result.startWith("error_")){ $("#errorMessage").html(result.substring(6)); } else { //返回的结果转换成JSON数据 var jsonObj = eval('('+result+')'); startTime = $("#startdate").val(); endTime = $("#enddate").val(); hour = jsonObj.hour; reason = jsonObj.reason; replaceDom(startTime,endTime,hour,reason); } } }); });
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How does ajax upload files without refreshing?


How to do it before Ajax returns data Loading waiting animation effect

The above is the detailed content of How to verify Ajax submission form parameters with jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!