Добрый день! Всем заранее спасибо,кто прочитает и может поможет. Делаю форму по этому примеру
http://tutorialzine.com/2010/04/carbon-signup-form/
Хочу слегка модифицировать,хочу чтобы по завершения проверки формы вместо перенаправления(как в статье) эти данные вылезали в блоке вверху страницы(AJAX без перезагрузки),как например вылезают блоки с ошибкой
Модифицированный JS CODE:
// Issuing a POST ajax request to submit.php (the action attribute of the form):
$.post($('#signupForm').attr('action'),$('#signupForm').serialize()+'&fromAjax=1',function(response){
if(!response.status)
{
// Some kind of input error occured
// Looping through all the input text boxes,
// and checking whether they produced an error
$('input[type!=submit]').each(function(){
var elem = $(this);
var id = elem.attr('id');
if(response[id])
showTooltip(elem,response[id]);
});
}
else {
$(response.html).hide().insertBefore('#signupForm').slideDown(900);
$('#body').val('');}
}
Модифицированный PHP:
if($_POST['fromAjax'])
{
if(count($errors))
{
$errString =
array();
foreach($errors as $k=>
$v)
{
// The name of the field that caused the error, and the
// error text are grouped as key/value pair for the JSON response:
$errString[]=
'"'.
$k.
'":"'.
$v.
'"';
}
// JSON error response:
die ('{"status":0,'.
join(',',
$errString).
'}');
}
function markup
($name,
$email,
$pass){
return '
<div class="comment" id="new">
<div class="name">'.
$name.
'</div>
<div class="date" title="Added at '.
$email.
'</div>
<p>'.
$pass.
'</p>
</div>
';
};
// JSON success response.
echo json_encode
(array('status'=>
1,
'html'=>markup
($_POST['name'],
$_POST['email'],
$_POST['pass'])));
exit;
}
Мне кажется дело в // JSON success response. Видно что то не так передаю или делаю. Заранее спасибо!