Jump to content

Recommended Posts

Snippet from index.html

 

<div id="contact-form" class="third-column">

      <h4>Drop us a line</h4>

      <form id="contactform" action="./contact-us.php.html" method="post" />

        <p>

          <input type="text" name="name" id="name" class="input-field" />

          <label for="name">Name *</label>

        </p>

        <p>

          <input type="text" name="email" id="email" class="input-field" />

          <label for="email">Email *</label>

        </p>

        <p>

          <textarea rows="4" cols="50" name="message" id="message"></textarea>

          <label for="message">Your message *</label>

        </p>

        <p>

         <a onclick="$('#contactform').submit(); return false;" href="" class="contact-button">SEND MESSAGE</a>

        </p>

      </form>

    </div>

contact-us.php.html


{"responseStatus":"err","responseMsg":"ajax"}

 

 

snippet from common.js


// init contact form validation and AJAX handling
  if ($("#contactform").length > 0) {
    $("#contactform").validate({ rules: { name: "required",
                                         email: { required: true, email: true },
                                         message: "required"},
                                messages: { name: "This field is required.",
                                            email: { required: "This field is required.",
                                                     email: "Please enter a valied email address."},
                                            message: "This field is required."},
                                submitHandler: function(form) {  $(form).ajaxSubmit({dataType: 'json', success: contactFormResponse}); }
                              });
  }
});

// handle newsletter subscribe AJAX response
function newsletterResponse(response) {
  if (response.responseStatus == 'err') {
    if (response.responseMsg == 'ajax') {
      alert('Error - this script can only be invoked via an AJAX call.');
    } else if (response.responseMsg == 'fileopen') {
      alert('Error opening $emailsFile. Please refer to documentation for help.');
    } else if (response.responseMsg == 'email') {
      alert('Please enter a valid email address.');
    } else if (response.responseMsg == 'duplicate') {
      alert('You are already subscribed to our newsletter.');
    } else if (response.responseMsg == 'filewrite') {
      alert('Error writing to $emailsFile. Please refer to documentation for help.');
    } else {
      alert('Undocumented error. Please refresh the page and try again.');
    }
  } else if (response.responseStatus == 'ok') {
    alert('Thank you for subscribing to our newsletter! We will not abuse your address.');
  } else {
    alert('Undocumented error. Please refresh the page and try again.');
  }
} // newsletterResponse

// handle contact form AJAX response
function contactFormResponse(response) {
  if (response.responseStatus == 'err') {
    if (response.responseMsg == 'ajax') {
      alert('Error - this script can only be invoked via an AJAX call.');
    } else if (response.responseMsg == 'notsent') {
      alert('We are having some mail server issues. Please refresh the page or try again later.');
    } else {
      alert('Undocumented error. Please refresh the page and try again.');
    }
  } else if (response.responseStatus == 'ok') {
    alert('Thank you for contacting us! We\'ll get back to you ASAP.');
  } else {
    alert('Undocumented error. Please refresh the page and try again.');
  }
} // contactFormResponse

This is a contact form. When I attempt to submit the form... I get the message "      alert('Error - this script can only be invoked via an AJAX call.');"

 

Any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/237948-ajax-call-issue/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.