title: Jquery validation messages from xml
body: <p>I am using Jquery <a href="http://docs.jquery.com/Plugins/validation" rel="nofollow">valdiation plugin</a> for validating the form at client side.
  I am fetching validation error messages from an xml file.</p>
  
  <pre class="lang-js prettyprint-override"><code>$("#"+form).validate({
      errorLabelContainer: "#dialogError", //msg_error
      wrapper: "li",
      rules: {
          txtInfringementID: {
              required: true,
              digits: true
          },
          txtLicenceNumber: {
              required: true            
          },
          txtDateOfOffence: {
              date: true,
              required: true
          }
      },
      messages: {
          txtInfringementID: {
              required:this.errorMessage("InfringementID","Required"),
              digits: "Inf Id must be numeric only"
          },
          txtDateOfOffence: {
              required: "please enter date of offence",
              date: "Date is not valid"
          },
          txtLicenceNumber:this.errorMessage("LicenceNumber", "Required"),
          txtSurname: this.errorMessage("DebtorSurname", "Required")
      }
  )};
  </code></pre>
  
  <p>errorMessage function is below.</p>
  
  <pre class="lang-js prettyprint-override"><code>this.errorMessage = function (Field, Rule) {
  
      var message;
      $.ajax({
          type: "GET",
          url: "../../../ErrorMessages.xml",
          dataType: "xml",
          success: function (xml) {
  
              $(xml).find("*[Name='" + Field + "']").each(function () {
                  message = $(this).find(Rule).text();
              });
          }
      });
  
      return message; **//I am using a debugger here**
  }
  </code></pre>
  
  <p>and the xml I am using is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;ErrorMessage&gt;
      &lt;Field Name="InfringementID"&gt;
          &lt;Required&gt;Infringement ID is required&lt;/Required&gt;
          &lt;Digit&gt;Infringement ID should be numeric only&lt;/Digit&gt;
      &lt;/Field&gt;
      &lt;Field Name="LicenceNumber"&gt;
          &lt;Required&gt;License Number is Mandatory&lt;/Required&gt;
      &lt;/Field&gt;
      &lt;Field Name="DebtorSurname"&gt;
          &lt;Required&gt;Debtor Surname is Mandatory&lt;/Required&gt;
      &lt;/Field&gt;
  &lt;/ErrorMessage&gt;
  </code></pre>
  
  <p>But the problem is that when I use debugger, I am getting messages from xml. If I don't use debugger, I am getting default message 'this field is required'. I think, the issue is <code>this.errorMessage()</code> is a asynchrounous request and this request is taking some time to complete. I tried to put some delay using <strong>setTimeout function</strong>. but I don't know where to put the time delay. Any thought process is welcomed.</p>
  
  <p>I am setting timeout like this.</p>
  
  <pre><code>required:setTimeout(this.errorMessage("InfringementID","Required"),10000),
  </code></pre>