title: How to prevent Client DOM XSS vulnerability in javascript?
body: <p>After checkmarx scan on my code,I am getting the below message.</p>
  <blockquote>
  <p>Method execute at line 23 of ...\action\searchFun.js  gets user input for the form element.</p>
  <p>This element’s value then flows through the code without being properly sanitized or validated and is eventually displayed to the user in function at line 28 of ../action/searchFun.js. This may enable a DOM XSS attack.</p>
  </blockquote>
  <p>Could some help me how to sanitize the above scenario to satisfy Checkmarx?
  Script as follows:</p>
  <pre><code>function searchAnnouncements(){
    $('#loadingAnnouncements').html('Loading...');
    var formData = $('form').serialize();
  
    jQuery.ajax({
      type: &quot;post&quot;,
      url:  &quot;bat.ajax&quot;,
      data: formData,
      cache: false,
      dataType: &quot;json&quot;,
      cache: false,
      success: function(json) {
        $('div.block').unblock();
        $('#loadingAnnouncements').html('');
        if (json.resultSize &gt; 0)
          $('#searchResults').html(json.searchResult);
      });
    },
  }
  </code></pre>