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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分