[英]js deleting submitted form data
The problem: Javascript function( which was premade by template) cleans the form data sent to me by php 问题:Javascript函数(由模板预先制成)可以清除php发送给我的表单数据
The php code: php代码:
<?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 . "\n\n" . 'Телефон: ' . $phone . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = @mail($email_to, $subject, $body);
echo json_encode($status);
die;
The javascript function code: javascript函数代码:
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. 如果没有js代码,则php会返回一行白屏,但是@mail会发送正常消息,但是当出现此代码时,淡入和淡出效果很好,但数据却为空。 The message in message and name is cyrylic if that is important.
如果消息和名称中的消息很重要,则该消息为cyrylic。
Please help me fix it(ie 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. 请帮助我修复它(即我既需要数据到达又要出现成功淡入,或者至少需要数据到达而没有.php白屏),或者只是解释一下我没有得到js代码是什么。 Thanks
谢谢
You haven't provided the data
argument for $.post
您尚未提供
$.post
的data
参数
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: 参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.