我想显示没有警报框的数据,但是我不知道该怎么做?提交表单后,必须显示成功消息而不使用警报框;它应该以普通文本显示。我添加了我的脚本代码和数据库代码。谁能帮我?我是jQuery的初学者。这是我的代码:
<script>
$(document).ready(function(){
$('#validate_form').parsley();
$('#validate_form').on('submit',function(event)
{
event.preventDefault();
if($('#validate_form').parsley().isValid())
{
$.ajax({
url:"db.php",
method:"POST",
data:$(this).serialize(),
beforeSend:function(){
$('#submit').attr('disabled','disabled');
$('#submit').val('submitting the value');
},
success:function(data){
$('#validate_form')[0].reset();
$('#validate_form').parsley().reset();
$('#submit').attr('disabled',false);
$('#submit').val('submit');
alert(data);
}
});
}
});
});
</script>
db.php
<?php
//action.php
sleep(2);
if(isset($_POST['first_name']))
{
$connect = new PDO("mysql:host=localhost;dbname=onlineshop", "root", "");
$data = array(
':first_name' => $_POST['first_name'],
':last_name' => $_POST['last_name'],
':email' => $_POST['email'],
':password' => $_POST['password']
);
$query = "
INSERT INTO tbl_register
(first_name, last_name, email, password)
VALUES (:first_name, :last_name, :email, :password)
";
$statement = $connect->prepare($query);
if($statement->execute($data))
{
echo 'Registration successfully completed';
}
}
?>
答案 0 :(得分:1)
将<span></Span>
或<Div></Div>
设置为要在HTML中显示普通文本的位置。
为范围或div提供ID
<div id ="displayMessage"> </div> `
然后在警报位置对代码进行更改。
<script>
$(document).ready(function(){
$('#validate_form').parsley();
$('#validate_form').on('submit',function(event)
{
event.preventDefault();
if($('#validate_form').parsley().isValid())
{
$.ajax({
url:"db.php",
method:"POST",
data:$(this).serialize(),
beforeSend:function(){
$('#submit').attr('disabled','disabled');
$('#submit').val('submitting the value');
},
success:function(data){
$('#validate_form')[0].reset();
$('#validate_form').parsley().reset();
$('#submit').attr('disabled',false);
$('#submit').val('submit');
$("#displayMessage").html(data);
}
});
}
});
});
</script>