使用 jquery 验证引擎为 ajax 验证传递多个字段

passing multiple fileds for ajax validation with jquery validation engine

我正在使用 jquery 验证引擎来验证表单输入。它工作正常。 我遇到这样一种情况,我要求用户提供国家和邮政编码,我需要验证国家和邮政编码的组合是否有效。

单独验证字段的代码工作正常,如下所示:

<p class="mediumlargefont add_margin_top">Please confirm your country:</p>
<input onclick="$('#postcode').validationEngine('showPrompt', 'Please select your country', 'load')"
    class="validate[required, custom[onlyLetterSp], maxSize[30], ajax[ajaxNameCallCountry]]" 
    type="text" name="country" id="autocomplete" value="[% IF country; country; END %]"/>
</div>
<div>
    <p class="mediumlargefont add_margin_top">Please enter your postcode:</p>
    <input maxlength="10" size="22"  
    onclick="$('#postcode').validationEngine('showPrompt', 'Please enter the postcode of your current location', 'load')"
    class="validate[condRequired[country], custom[onlyLetterNumberSpHy], maxSize[10], ajax[ajaxNameCallPostcode]]" 
    type="text" name="postcode" id="postcode" data-prompt-position="centerRight"/>
</ul>

我想知道的是,有没有办法在我验证邮政编码时,通过 ajax 调用将国家/地区输入的当前值也传递给后端?这将使我能够验证组合。

顺便说一句,验证引擎的 JS 如下所示:

$(document).ready( function(){
    $("#postcodeForm").validationEngine('attach', 'autoHidePrompt', {
        scroll: "false",
        ajaxFormValidation : "true"
    });
});

当然,10分钟后我找到了答案。希望对其他人有帮助。

在 ajax 选择器的定义中添加 extraDataDynamic

例如,

"ajaxUserCall": {
    "url": "ajaxValidateFieldUser",
    "extraData": "name=eric",
    "extraDataDynamic": ['#user_id', '#user_email'],
    "alertText": "* This user is already taken",
    "alertTextOk": "All good!",
    "alertTextLoad": "* Validating, please wait"
},