我是 jQuery 新手,如果成功更改数据库,我喜欢做一个简单的任务来显示一条消息。
JavaScript
var dataString = 'textareaannoun='+ textareaannoun;
$(function(){
$('#formboard').submit(function(){
$.ajax({
type : 'post',
url : 'edit_announ.php',
dataType: 'json',
data: $(this).serialize(),
success: function(data){
if(data.error){
$('#error').css('display','block');
}else {
$('#accept').show();
$('#error').hide();
}
}
});
return false;
});
});
PHP + HTML
<div id='accept' align='center'><h2><img id='checkmark' src='images/successM.png' /> Alterado com sucesso!</h2></div>
<div id='error' align='center'><h2><img id='checkmark' src='images/errorM.png' /> Verifique os dados inseridos!</h2></div>
<h4>Alterar código do anúnio:</h4>
<form id="formboard" name="formboard" method='post' action="">
<textarea name="textareaannoun" id="textareaannoun"><?php echo $announc[0][0]; ?> </textarea>
<div class="submit-button">
</br>
<input type="submit" name="inserir" id="inserir" value="Alterar" />
<a href="main.php"><input type="button" name="voltar" value="Voltar" /></a>
</div>
</form>
<?php
if (!empty($_POST['inserir'])) {
$textareaannoun = $_POST['textareaannoun'];
if(!empty($textareaannoun))
{
echo json_encode(array(
'error' => false,
));
//exit;
$changes = $announc[0][1] + 1;
editAnnounc($textareaannoun);
}else{
echo json_encode(array(
'error' => true,
'msg' => "You haven't completed all required fileds!"
));
//exit;
}
}
结果似乎是隐藏的 div。但结果是这样的:
http://i.stack.imgur.com/icZUd.png
有人可以帮我一点吗?