title: Wordpress post-only ajax form gives jQuery error?
body: <p>I have a wordpress site that has an ajax newsletter signup form. On the  homepage everything runs error free :-) On a blog post page, I get this error: </p>
  
  <p>[Error] TypeError: e.indexOf is not a function. (In 'e.indexOf(" ")', 'e.indexOf' is undefined)
      (anonymous function) (jquery-3.3.1.min.js:2:31048)</p>
  
  <p>[Error] TypeError: a.parent("a").size is not a function. (In 'a.parent("a").size()', 'a.parent("a").size' is undefined)
      (anonymous function) (jquery-3.3.1.min.js:2:31048)</p>
  
  <p>The HTML:</p>
  
  <pre><code>&lt;div class="newsletter-section"&gt;
          &lt;div id="form-messages"&gt;&lt;/div&gt;
  
      &lt;div class="form-div d-flex justify-content-center"&gt;
          &lt;form id="ajax-contact" method="POST" action="mailer.php"&gt;
  
              &lt;input type="text" class="" id="email" name="email" required placeholder="Sign up for our newsletter"&gt;
              &lt;div class="btn-center"&gt;
                  &lt;button type="submit"&gt;Sign up&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  
      &lt;/div&gt;  
  &lt;/div&gt;
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>$(function() {
  
  // Get the form.
  var form = $('#ajax-contact');
  
  // Get the messages div.
  var formMessages = $('#form-messages');
  
  // Set up an event listener for the contact form.
  $(form).submit(function(e) {
      // Stop the browser from submitting the form.
      e.preventDefault();
  
      // Serialize the form data.
      var formData = $(form).serialize();
  
      // Submit the form using AJAX.
      $.ajax({
          type: 'POST',
          url: $(form).attr('action'),
          data: formData
      })
      .done(function(response) {
          // Make sure that the formMessages div has the 'success' class.
          $(formMessages).removeClass('error');
          $(formMessages).addClass('success');
  
          // Set the message text.
          $(formMessages).text(response);
  
          // Clear the form.
          $('#email').val('');
      })
      .fail(function(data) {
          // Make sure that the formMessages div has the 'error' class.
          $(formMessages).removeClass('success');
          $(formMessages).addClass('error');
  
          // Set the message text.
          if (data.responseText !== '') {
              $(formMessages).text(data.responseText);
          } else {
              $(formMessages).text('Oops! Er loopt iets fout. Je boeking is niet verzonden.');
          }
      });
  
  });
  </code></pre>
  
  <p>});</p>
  
  <p>Can anyone help me?</p>
  
  <p>Thank you,
  Fred</p>