I have a custom form set up and have been trying to get it to submit using AJAX. I have the below code which seems to submit successfully, however I'm not seeing anything show up in the submissions logs for the custom form.
$(function() {
$("#contact_form form").submit(function(e) {
//process form here
var $form = $(this);
var urlSend = $form.attr("action");
var dataSend = $form.serialize();
var encodingType = $form.attr("enctype");
$.ajax({
type: "POST",
//URL of submit script?
url: urlSend,
contentType: encodingType,
data: dataSend,
success: function() {
$('#contact_form').html("<div id='message'></div>");
$('#message').html("<p>Form Submitted!</p>")
.hide()
.fadeIn(1500, function() {
$('#message').append("<p>Woo</p>");
});
}
});
e.preventDefault();
});
});
The only difference I am able to see between it submitting with/without AJAX is in the headers.
without AJAX:
Request Headers
POST ###HTTP/1.1
Host: ###
Proxy-Connection: keep-alive
Content-Length: 680
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: ###
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary2nTBFksqvDiDGTbX
Referer: ###
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cookie: _fby_site_=1%7Cact.gov.au%7C1418858226%7C1418858226%7C1418858226%7C1418858226%7C1%7C1%7C1; __utma=213350664.1026509165.1416192371.1422495190.1422508242.2; __utmz=213350664.1422495190.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __atuvc=0%7C6%2C0%7C7%2C0%7C8%2C0%7C9%2C9%7C10; _gat=1; SQ_SYSTEM_SESSION=bo2dutmpgs4vp96u96ocln1le0; _ga=GA1.3.1026509165.1416192371
Request Payload
------WebKitFormBoundary2nTBFksqvDiDGTbX
Content-Disposition: form-data; name="SQ_FORM_704745_PAGE"
1
------WebKitFormBoundary2nTBFksqvDiDGTbX
Content-Disposition: form-data; name="form_email_704745_referral_url"
------WebKitFormBoundary2nTBFksqvDiDGTbX
Content-Disposition: form-data; name="q704745:q1"
11
------WebKitFormBoundary2nTBFksqvDiDGTbX
Content-Disposition: form-data; name="q704745:q2"
22
------WebKitFormBoundary2nTBFksqvDiDGTbX
Content-Disposition: form-data; name="q704745:q3"
33
------WebKitFormBoundary2nTBFksqvDiDGTbX
Content-Disposition: form-data; name="form_email_704745_submit"
Send
------WebKitFormBoundary2nTBFksqvDiDGTbX--
Request Headers
POST ###HTTP/1.1
Host: ###
Proxy-Connection: keep-alive
Content-Length: 120
Accept: */*
Origin: ###
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
Content-Type: multipart/form-data
Referer: ###
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cookie: _fby_site_=1%7Cact.gov.au%7C1418858226%7C1418858226%7C1418858226%7C1418858226%7C1%7C1%7C1; __utma=213350664.1026509165.1416192371.1422495190.1422508242.2; __utmz=213350664.1422495190.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __atuvc=0%7C6%2C0%7C7%2C0%7C8%2C0%7C9%2C9%7C10; _gat=1; SQ_SYSTEM_SESSION=bo2dutmpgs4vp96u96ocln1le0; _ga=GA1.3.1026509165.1416192371
Request Payload
SQ_FORM_704745_PAGE=1&form_email_704745_referral_url=&q704745%3Aq1=41241&q704745%3Aq2=412412412412&q704745%3Aq3=53456346
I'm assuming it's something to do with the extra content-type and WebKitFormBoundary############## wrapping the posted data, but I'm not sure how to actually add that in?
I have been able to get the AJAX submit working using a
plugin, but I am hoping to get it working without.