=====[Before I liked the asynchronous method. I feel that when writing the verification, the thinking is coherent, and the request is very smooth after verification. 】
<div id="btn_save_baseInfo" class="btn_save"> <input type="submit" value="保存" class="btn btn-default btn-lg btnCustom" /> <%-- 同步 --%> <%--<input id="submitId" type="button" value="保存" class="btn btn-default btn-lg btnCustom" /> 异步--%> </div>
=====The boss said: the security of asynchronous submission may be relatively low. After checking, only js code can be found to intercept Ajax requests. No interception of synchronous action requests was found.
Learned: Asynchronous or synchronous are http requests. Only the submission method is different. Security mainly depends on the background system.
BUT: The industry is used to thinking that asynchronous requests are relatively less secure. Then use synchronous mode. [Lest it has to be synchronized like it is now]
=====
form:
<form id="newform" class="formbox" action="/promotion/media/create" method="post" enctype="multipart/form-data" onsubmit="return checkForm();" > <jsp:include page="/WEB-INF/view/jsp/clickcube/admin/media/form.jsp"/> </form>
check:
<script> //================"Synchronous submission of the form is not ok function checkForm(){ // 1. Media name ===ok $("#mediaNameTip").remove(); // remove last tip var val = $("#mediaName").val(); // alert("val0:"+val); if(val.trim()==undefined || val.trim()==null || val.trim().length<1){ // alert("val2:"+val); $("#mediaName").after("<span id='mediaNameTip' style='color: red'>必填</span>"); return false;//Prevent submission } // 2、incomWay var incomWayChecked=$("input[type='radio'][name='incomeWay']:checked");//alert("incomWayChecked:"+incomWayChecked);//未选 也不是undefined var incomWayCheckedVal = incomWayChecked.val();//alert("incomWayCheckedVal:"+incomWayCheckedVal);return /* 00, when changing: the first-level radio is not selected. ====="[Only the second-level radio needs to judge this when changing. Level 1 radio change, incomWay must not be undefined] Prompt that the first-level radio is required. Remove all possible Tip and InputValue. Uncheck the secondary radio. ====》easy。 */ if(undefined == incomWayCheckedVal){ //style='margin-left: 4px' removeAll_TipAndValue(); //Avoid the same situation, multiple tips. $("#incomeWayFont").after("<font color='red' id='incomeWayTip' style='float: left; ' >必填</font>");//必须在remove后 $('input:radio[name="cpcType"]').removeAttr('checked'); return false; } /* 01. When changing: the first-level radio has been selected: incomWay=0. Delete all Tip and InputValue that may have secondary radios: cpc price clear ==== ok Uncheck the secondary radio. ==== ok ====》easy。*/ if("0".indexOf(incomWayCheckedVal) != -1){ //String incomWay等于0 removeAll_TipAndValue_Cpc(); $('input:radio[name="cpcType"]').removeAttr('checked'); //=====》add for submit if( !validateRate()){ return false; }else { // submitform(); return true; } } /* 02. When changing: Level 1 radio has been selected: incomWay=1. [The most complicated is here. 】 */ if("1".indexOf(incomWayCheckedVal) != -1){ //String incomWay等于1 var cpcTypeVal = $("input[type='radio'][name='cpcType']:checked").val(); /* 02.00, when change: the first-level radio is not selected. ====="[Only the second-level radio needs to judge this when changing. Level 1 radio change, incomWay must not be undefined] Prompt that the secondary radio is required. Remove all possible Tip and InputValue. Uncheck the secondary radio. ====》easy。 */ if(undefined == cpcTypeVal){ //style='margin-left: 4px' removeAll_TipAndValue(); //Avoid the same situation, multiple tips. $("#cpcWayDD").append("<font color='red' id='cpcTypeTip' >Must choose a CPC</font>");//Must be after remove $('input:radio[name="cpcType"]').removeAttr('checked'); return false; } /* 02.1 change: the secondary radio selects cpcType=0 No other action is required. */ if("0".indexOf(cpcTypeVal) != -1){ //No other operations are required. //=====》add for submit if( !validateClickUnitPrice()){ return false; }else { //submitform(); return true; } } /*02.2 change: the secondary radio selects cpcType=1 Delete Tip and InputValue of cpcType=0: clickUnitPriceTip is cleared. clickUnitPrice is cleared. */ if("1".indexOf(cpcTypeVal) != -1){ removeAll_TipAndValue_Cpc();//That is, Tip and InputValue of cpcType=0 // submitform(); return true; } } /* ==========[Verification end] */ return true; } </script>