dongliehuan3925 2014-04-01 04:04
浏览 125
已采纳

使用ajax发送html数据和表单并保留在当前页面上

I'm trying to send an email the contains html table data as well as the input from the user. This is what the email is displaying at the moment.

Device - iPad $14000

Your App Will Cost Approximately : $14000

FromEmail

The input from user is not being displayed for some odd reason, I've changed the function to .click & .form but this sends only the input from the user. I really want both of these things to send.

here is the html

<div class="total-inner">
    <table class="total-table" id="table">
        <tbody>
            <tr>
                <td>Device - iPad</td>
                <td>$14000</td>
            </tr>
        </tbody>    
    </table>

    <hr><br>

    <div class="total-text-wrap">
        <p>Your App Will Cost Approximately  :  $<span class="total">0</span></p>   
    </div>

    <br><hr>
</div>

<div class="form-wrap">
    <form method="post" class="quote-form" action="server.php">
        <span>Company:<input type="text" name="name"></span>
        <span>Email:<input type="text" name="email"></span>

        <br>

        <button class="total-button" id="send-quote" type="submit">SEND</button>
    </form>
 </div>

 <div class="button-wrap">
    <a href="index1.html">
        <button class="total-button" input-type="submit">RESTART</button>
    </a>
    <button class="total-button" id="quote-advance">GET IN TOUCH</button>
    <button class="total-button">SAVE PDF</button>
 </div>

My Javascript/jquery

  Var   contactNode    = $('#quote-advance'),
        quoteNode      = $('.quote-form'),
        tableData      = [],
        totalData      = [];

 contactNode.click(function(){
            $(".form-wrap").slideDown(750);
            $(function(){
                    totalTableNode.each(function(){
                        tableData.push($(this).html());
                    });

                    totalText.each(function(){
                        totalData.push($(this).html());
                    });
            quoteNode.submit(function(e){   
                $.ajax({
                  type : "POST",
                  url : 'server.php',
                  data : "content=" + tableData + totalData,
                  success: function(data) {
                      alert('Email Sent');// alert the data from the server
                  },
                  error : function() {
                  }

            });
                e.preventDefault();
            });

        });
    });

and the php

<?php 
$to  = 'test@gmail.com';
$subject = 'Testing';
$message = $_REQUEST['content'];
$message .= 'From' . $_POST["name"];
$message .= 'Email' . $_POST["email"];
$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
mail($to, $subject, $message, $headers);
?>

To reiterate, the email that I'm receiving at the moment contains ONLY the html table data. & if i change the quoteNode function to .click or .form. The email sends the input data, but not the html table data & redirects to blank server.php file (I want it to alert & stay on the current page as well as send the user input & the html table data). Please help! I'm stumped!!! Cheers!

  • 写回答

1条回答 默认 最新

  • douxiapi4381 2014-04-02 07:19
    关注

    looks like the data isnt filled correctly. It could be submitted before it filled. Can you try this:

    EDIT (works at my server):

    HTML/ JS

    <div class="total-inner">
        <table class="total-table" id="table">
            <tbody>
                <tr>
                    <td>Device - iPad</td>
                    <td>$14000</td>
                </tr>
            </tbody>    
        </table>
    
        <hr><br>
    
        <div class="total-text-wrap">
            <p>Your App Will Cost Approximately  :  $<span class="total">0</span></p>   
        </div>
    
        <br><hr>
    </div>
    
    <div class="form-wrap">
        <form method="post" class="quote-form" action="#">
            <span>Company:<input id="name" type="text" name="name"></span>
            <span>Email:<input id="email" type="text" name="email"></span>
    
            <br>
    
            <input class="total-button" id="send-quote" type="submit" value="submit">
        </form>
     </div>
    
     <div class="button-wrap">
        <a href="index1.html">
            <button class="total-button" input-type="submit">RESTART</button>
        </a>
        <button class="total-button" id="quote-advance">GET IN TOUCH</button>
        <button class="total-button">SAVE PDF</button>
     </div>
    <script type="text/javascript" src="jQuery.js"></script>    
     <script>
    var contactNode    = $('#quote-advance'),
            quoteNode      = $('.quote-form');
    
    
    
    quoteNode.submit(function( event ) { 
      $(".form-wrap").slideDown(750);
    
    var dataTable = "";
    
    $('.total-table td').each(function() {
        dataTable += $(this).html();    
    });
    
    var name =$("#name").val(); 
    var email = $("#email").val();
    data= 'name=' + name + '&email=' + email + '&content=' + dataTable ;        
      alert(dataTable);
        $.ajax({
          type : "POST",
          url : 'server.php',
          data : data,
          success: function(data) {
              alert('Email Sent');// alert the data from the server
          },
          error : function() {
          }
        });
    event.preventDefault();
    });
    </script>
    

    PHP

    <?php 
    $to  = 'mail@gmail.com';
    $subject = 'Testing';
    $message = $_POST['content'];
    $message .= 'From' . $_POST["name"];
    $message .= 'Email' . $_POST["email"];
    $headers  = 'MIME-Version: 1.0' . "
    ";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "
    ";
    mail($to, $subject, $message, $headers);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名