Hi there folks I have a jquery script to submit a form and if successful it sends json output back.
function subscribe(email, city){
var email = $('input#email').val();
var city = $('select#citySelect').val();
$.ajax({
url: 'http://www.amazingvouchercodes.co.uk/avc_dev/subscribe/subscribeTo',
type: 'post',
data: 'email='+email+'&city='+city,
dataType: 'json',
success: function(json){
window.location.href = json['url'];
$('#notifications').append('<div class="success">'+json['success']+'</div>');
}
});
}
the problem I have is that it is displaying the notification > json success before the redirect after redirect the notification doesnt show, is there a way to show the notification after the redirect?
Thanks all help is appreciated 🙂
Joe
Like AlienWebguy suggested,
It is because you are loading a new page, so any JavaScript gets reset.
I think the best way would be to have an element set in your layout/header that displays messages on the top of your screen (like how this site notifies you of something in the orange bar) if any are pending. So on your Ajax page, you set a notification (session/cookie) variable. Then the next time a page loads (after your redirect), the layout will know there is a notification pending, it displays it in the layout/header and clears it (so it only shows up once.)