Jquery Ajax没有发送到php

时间:2017-01-16 17:26:57

标签: php jquery ajax

我尝试过很多东西,但无法让它发挥作用。传递给ajax代码100%的变量在其中包含字符串。我已经逐位测试了代码,直到ajax代码和之后。之前的一切证明变量不会“丢失”,它们会显示正确的值。我甚至尝试了一个简单的“测试”字符串,而不使用任何其他数据通过ajax发送。 PHP代码仍然没有收到任何数据。 根据我的测试,字面上没有POST数据传递给PHP脚本。 php脚本在同一页面上。 该页面名为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 );

0 个答案:

没有答案