How to send external form POST data through AJAX

I have a web form, simple HTML / PHP that works by itself but when it is passed onto the template page via the below AJAX call -- the post data is missing on submission. This HAS got to be a param I'm missing below.

$(document).ready(function() {

$('#toggle3').click(function(){
    var tog = $('.toggle');
    $.ajax({
        type: 'POST',
        url: '/mysimplewebform.php',
        success: function (fields){
            tog.html(fields);
            tog.slideToggle(1000);
        }
    });
  });
});

The request is sent. And upon submission I receive email, everything but the selected post data via form is sent. Below is the PHP.

<?php
    $backwheel = $_POST['backwheel'];
    $frontwheel = $_POST['frontwheel'];
    $form_message = "backwheel:".$backwheel." frontwheel:".$frontwheel." nMessage: ". " You just recieved a new custom order via your Customizer!"."nFullCustomURL: ".$_SERVER['HTTP_REFERER'];

  mail("email@gmail.com", "Your Website Something", $form_message, "From: Capn Ron (New Order!)" );

  if (isset($_POST['submit']))

    {   
echo "<script>
alert('Thanks for your Order!');
window.location.href='http://www.website.com';
</script>";       
    }
?> 

You're not missing a param. From your code, #toggle3 appears to be button since the click event is bound to it. So, if you try to serialize it, it will certainly return nothing. You have to serialize the surrounding form which is easily achieved by using jQuery's closest() function; ie:

$(document).ready(function() {

$('#toggle3').click(function(){
    var tog = $('.toggle');
    $.ajax({
        type: 'POST',
        url: '/mysimplewebform.php',
        data: $(this).closest('form').serialize(),
        success: function (fields){
            tog.html(fields);
            tog.slideToggle(1000);
        }
    });
  });
});
链接地址: http://www.djcxy.com/p/45632.html

上一篇: 我可以测试Sinatra post方法是否成功保存到YAML商店?

下一篇: 如何通过AJAX发送外部表单POST数据