Тема: setTimeout в ajax
Показать сообщение отдельно
  #2 (permalink)  
Старый 28.12.2013, 08:36
Профессор
Отправить личное сообщение для Rise Посмотреть профиль Найти все сообщения от Rise
 
Регистрация: 07.11.2013
Сообщений: 457

Вообще-то чего то ты перемудрил, вот тебе минимум:
<style>
#processComment {
	display: none;
	position: fixed;
	padding: 10px;
	background: #ccc;
	text-align: center;
}
</style>

<div id="processComment"></div>
<textarea id="textComment" name="textComment"></textarea>
<button id="addComment">Добавить</button>
<div id="allComments"></div>

<script>
$('#addComment').click(function() {  
	var process = $('#processComment');
	$.ajax({
		type: 'post',
		url: 'comment.php',
		data: $('#textComment').serialize(),
		dataType: 'html',
		beforeSend: function() { 
			process.text('Добавляется...').fadeIn();
		},
		error: function() {
			process.text('Ошибка! Не добавлен').delay(5000).fadeOut();
		},
		success: function(data) { 
			$('#allComments').prepend(data);
			process.text('Спасибо! Добавлен').delay(5000).fadeOut();
		}
	});
});
</script>

$_POST['textComment']
Ответить с цитированием