Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to complete $.get() when a form is submitted using jQuery
    primarykey
    data
    text
    <p>I am using a third party shopping cart that sends a registration form to a .cgi script.</p> <p>I want to send information from that form to me, and the customer via a jQuery $.get() function call.</p> <p>The $.get calls a registration.mail.php script.</p> <p>The problem is that the form submitting seems to cancel out the ajax call before the ajax call can be completed.</p> <p>I can think of some inelegant solutions, and I have decided, because I'm about to travel, to use a counter and make the user click 'Register' twice. This solution hurts my soul obviously.</p> <p>Here's the Javascript, that lives in the footer:</p> <pre><code>&lt;script type="text/javascript"&gt; var getsuccess = false; $(document).ready(function() { $('form#registerWholesale').bind('submit', function() { $email = $('#email').val(); $username = $('#contactname').val(); $company = $('#company').val(); $phone = $('#billphone1').val(); $message = "A new customer has registered at the wholesale website. \n "; $message += "They have the username of: " + $username + ". \n"; $message += "Their company is: " + $company + ". \n"; $message += "Their email is: " + $email + ". \n"; $message += "Their phone is: " + $phone + ". \n"; $message += "Please help them ASAP. You can access the back end of the site at: http://location of website admin backend"; $.get('/mail.php', {from: 'orders@OurCompany.com', message: $message, email: $email, username: $username, company: $company}, function(data, textStatus, xhr) { getsuccess = true; }); if (getsuccess) { return true; }else{ return false; } }); &lt;/script&gt; </code></pre> <p>And here is the registration.mail.php code.</p> <pre><code>&lt;?php //Vendor email (to us) $to = "ouremail@OurCompany.com"; $subject = "URGENT--New Registration--URGENT"; $message = htmlentities($_GET['message'], ENT_QUOTES, 'UTF-8'); //$message = $_GET['message']; $from = htmlentities($_GET['from'], ENT_QUOTES, 'UTF-8'); //$from = trim($_GET['from']); $headers = "From: $from"; mail($to,$subject,$message,$headers); //echo "Mail Sent."; //Customer email (to them) $to_cust = htmlentities($_GET['email'], ENT_QUOTES, 'UTF-8'); $subject_cust = 'OurCompany Online Wholesale Account Request Recieved'; $message_cust = "Thank you for you interest in OurCompany's new wholesale website. \n\n We have received your request to create an account. In order to obtain a wholesale account, a OurCompany representative must verify your account information and details by telephone. OurCompany will contact you within 1 business day at the telephone number that we have on file, or feel free to give us a call at 1-xxx-xxx-xxxx anytime if you would like a more rapid approval. \n\n Thanks Again ~ OurCompany"; $headers_cust = "From: orders@OurCompany.com"; mail($to_cust,$subject_cust,$message_cust,$headers_cust) ?&gt; </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload