1227 Posted May 31, 2011 Share Posted May 31, 2011 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 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/237946-ajax-call-issue/ Share on other sites More sharing options...
gristoi Posted May 31, 2011 Share Posted May 31, 2011 {"responseStatus":"err","responseMsg":"ajax"} if (response.responseStatus == 'err') { if (response.responseMsg == 'ajax') { alert('Error - this script can only be invoked via an AJAX call.'); your code is doing exactly what it is coded to do. What is the problem? Link to comment https://forums.phpfreaks.com/topic/237946-ajax-call-issue/#findComment-1222827 Share on other sites More sharing options...
1227 Posted May 31, 2011 Author Share Posted May 31, 2011 {"responseStatus":"err","responseMsg":"ajax"} if (response.responseStatus == 'err') { if (response.responseMsg == 'ajax') { alert('Error - this script can only be invoked via an AJAX call.'); your code is doing exactly what it is coded to do. What is the problem? I need the form to submit and send to an email.. how would I do so? Link to comment https://forums.phpfreaks.com/topic/237946-ajax-call-issue/#findComment-1223180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.