0

Currently I have this, which works nicely - it's an email signup list which returns a successful response or error, as appropriate.

$.ajax({ type: "POST", url: "mailing_list/mailing_list_add2.php", data: dataString, success: function(response) { $('#emailform').html("<div id='display_block'></div>"); $('#display_block') .hide() .fadeIn(500, function() { $('#display_block').html(response) }); } }); return false; }); 

The form is in a div with ID "emailform" and the "display_block" is the response. What I need is for the response to automatically disappear after a short time and for the form to fade back in. I've tried a few things but nothing that has worked yet.

Any help on what to add to the above code would be appreciated.

4 Answers 4

1

Assuming your initial html is like,

<div id="emailform"> <form> ... </form> </div> 

you can proceed like this,

.ajax({ type: "POST", url: "mailing_list/mailing_list_add2.php", data: dataString, success: function(response) { var backupHtml = $('#emailform').html(); $('#emailform').html("<div id='display_block'></div>"); $('#display_block') .hide() .html(response) .fadeIn(500, function() { $(this).fadeOut(5000,function(){ $('#emailform').html(backupHtml); }); }); } }); 
Sign up to request clarification or add additional context in comments.

6 Comments

The response faded out ok, but emailform didn't appear again.
i updated the jquery and i suppose ur html markup looks like the above right?
Sorry, when I tried it the first time I didn't add the var backupHtml. Thanks again...
One additional thing I noticed, when the form re-appears it won't re-submit. Click the button and nothing happens.
that will depend on how you are handling the form submission.. I mean which function you are calling and the like..
|
1

There is nothing inside display_block when you fade it in. Its just empty, I changed the code:

$.ajax({ type: "POST", url: "mailing_list/mailing_list_add2.php", data: dataString, success: function(response) { var backedup = $('#emailform').html(); // Take a snapshot of whats inside the emailform $('#emailform').html("<div id='display_block'></div>"); $('#display_block') .hide() .html(response) // New line! .fadeIn(500,function (){ // After we finsish the fadeIn $('#emailform').hide().html(backedup).fadeIn(500); // Reset the old content and fade it in });​ } }); return false; }); 

I created a JSFiddle for you http://jsfiddle.net/XHkWr/1/

1 Comment

It faded in and displayed ok though, what I wanted was for it to fade out and the emailform fade back in.
0

To do instead of all mumbo jumbo.

$('#emailform').html("<div id='display_block'></div>"); $('#display_block').hide().html(response).stop().fadeIn(500); 

5 Comments

but the OP has the display_block div inside the emailform div.. your code doesn't handle that
@achusonline, Why is that? Am i missing something?
in his code, he updates the emailform div with display_block div and in it he places the response.. So how does the above code handle updating the emailform div content to the original form?
@achusonline, I think you missed my point, I will update to make it clearer
pardon me, but I still don't see how you will bring back the original state of the emailform div? You are updating the html of that div.
0

I would say, that this would be a correct solution:

$.ajax({ url: 'mailing_list/mailing_list_add2.php', type: 'post', data: dataString, success: function(data, textStatus, jqXHR) { var $emailForm = $('#emailform').html(); $('#emailform').html('<div id="display_block"></div>'); $('#emailform').hide().html(data).fadeIn(500).delay(3000).fadeOut(500, function() { $('#emailform').html($emailForm); }); return false; }, error: function(jqXHR, textStatus, errorThrown) { var $emailForm = $('#emailform').html(); $('#emailform').html('<div id="display_block"></div>'); $('#display_block').hide().html(textStatus).fadeIn(500).delay(3000).fadeOut(500, function() { $('#emailform').html($emailForm); }); return false; } }); 

Result here: http://jsfiddle.net/p9URt/2/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.