Jquery Ajax not sending through to php

212
January 30, 2017, at 00:47 AM

I have tried many thing but cannot get this to work. The variables that are passed to the ajax code 100% have string within them. I have tested the code bit by bit until the ajax code and after. Everything before proves that the variables do no get 'lost' they display the correct values. I even tried a simple "test" string without using ANY other data to be sent through ajax. Still no data gets received by the PHP code. Based on my test literally no POST data is being passed through to the PHP script. The php script is on the same page. The page is called slate_designer.php

jquery:

$('#submit').on('click', function () {
var firstname = $('#firstname').val();
var lastname = $('#lastname').val();
var email = $('#email').val();
var tel = $('#tel').val();
    var slate = $( '#slate' ).html();
    var dataToSend = {
    "firstname" : firstname,
    "lastname" : lastname
};
var serialized = dataToSend.serialize();
$.ajax({
        url: 'slate_designer.php',
        type: 'POST',
        dataType:'json',
        data: serialized 
    });

php:

if(isset($_POST["firstname"])){
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email_address = $_POST["email"];
$phone_num = $_POST["tel"];
$comment = $_POST["comment"];
$slate = $_POST["slate"];
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=utf-8\n";
$headers .= "From:" . $email_address;
$headers .= "To: sergey95@gmail.com";
$message = "";
$message = "Name: " . $firstname . " " . $lastname . "\n";
$message .= "Email: " . $email_address . "\n";
$message .= "Phone Number: " . $phone_num . "\n";
$message .= "Message: " . $comment . "\n";
$message .= "Slate: \n" . $slate . "\n"; 

$to = 'email@gmail.com';
$subject = 'Order';
wp_mail( $to, $subject, $message );
READ ALSO
vertical slider with horizontal slides with jquery

vertical slider with horizontal slides with jquery

I have a product which have a multiple imageson top or bottom click i want to change the product

242
How to modify the “asc“ ”desc" schema in jQuery's legacy Datatable sorting

How to modify the “asc“ ”desc" schema in jQuery's legacy Datatable sorting

I have a table that with one column of strings, but my strings are in the following format: A1, A2, A12, A100, A200, A20

239
JavaScript error: Invalid Token when using ReCaptcha API

JavaScript error: Invalid Token when using ReCaptcha API

I have recently applied on my website an invisible Google ReCaptcha, but it is showing Unexpected Error: Invalid token= when I use the following code:

499
A sticky menu bar, which starts at the bottom and then stays at the top

A sticky menu bar, which starts at the bottom and then stays at the top

I'm making this single-page site where on the first opening, the whole screen is filled with a large image, with the menu bar on the bottom of the screen

196