drn34916 2014-10-23 15:17
浏览 40
已采纳

js删除提交的表格数据

The problem: Javascript function( which was premade by template) cleans the form data sent to me by php

The php code:

<?php
    header('Content-type: application/json');
    $status = array(
        'type'=>'success',
        'message'=>'GJ '
    );

    $name = @trim(stripslashes($_POST['name'])); 
    $phone = @trim(stripslashes($_POST['phone'])); 
    $subject = @trim(stripslashes($_POST['subject'])); 
    $message = @trim(stripslashes($_POST['message'])); 

    $email_to = 'email@email.com';//replace with your email

    $body = 'Name: ' . $name . "

" . 'Телефон: ' . $phone . "

" . 'Subject: ' . $subject . "

" . 'Message: ' . $message;

    $success = @mail($email_to, $subject, $body);

    echo json_encode($status);
    die;

The javascript function code:

var form = $('.contact-form');
form.submit(function () {'use strict',
    $this = $(this);
    $.post($(this).attr('action'), function(data) {
        $this.prev().text(data.message).fadeIn().delay(3000).fadeOut();
    },'json');
    return false;
});

When there's no js code php returns white screen with a line but the @mail sends normal message, but when there is this code fade in and out works good, but the data arrives empty. The message in message and name is cyrylic if that is important.

Please help me fix it(i.e. i need both data arriving and success fade-in appearing or at least data arriving with no .php white screen) or just explain what the js code does i don't get it. Thanks

  • 写回答

1条回答 默认 最新

  • dpwdldgn43486 2014-10-23 15:25
    关注

    You haven't provided the data argument for $.post

    Try

    var form = $('.contact-form');
    form.submit(function () {'use strict',
        var $this = $(this);    
        $.post($(this).attr('action'), $this.serialize(), function(data) {
            $this.prev().text(data.message).fadeIn().delay(3000).fadeOut();
        },'json');
        return false;
    });
    

    References:

    jQuery.post() Docs

    jQuery.serialize() Docs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么