godsent Posted June 14, 2009 Share Posted June 14, 2009 I'm sending post request and receiving the message and then trying to use that message at fade in/out div, but i making mistake in code. This code looks like this and it works fine: <script type="text/javascript"> $(document).ready(function() { $('#show-alert').click(function() { $.post("handlers/register.php", { username: $('#u11').val(), password: $('#u12').val() }, function(data){ document.getElementById("register_respond").innerHTML=data; }); }); }); </script> but then i trying to use $('<div class="quick-alert">' + data + '</div>') .insertAfter( $(this) ) .fadeIn('slow') .animate({opacity: 1.0}, 3000) .fadeOut('slow', function() { $(this).remove(); }); instead of document.getElementById("register_respond").innerHTML=data; it aint working. And if i try to create variable and then set it to data(return from POST) and use it as the div information it will show wrong information. Because it creates div without obtaining information in time. Quote Link to comment https://forums.phpfreaks.com/topic/162120-jquery-post-and-use-the-return/ Share on other sites More sharing options...
RichardRotterdam Posted June 14, 2009 Share Posted June 14, 2009 the following does not make much sense $('<div class="quick-alert">' + data + '</div>') the dollar function you mostly use as css selector if you want to use it to get an element by id use the following $('#register_respond').html(data); What should be the result btw? Quote Link to comment https://forums.phpfreaks.com/topic/162120-jquery-post-and-use-the-return/#findComment-855509 Share on other sites More sharing options...
godsent Posted June 14, 2009 Author Share Posted June 14, 2009 it should print "account created", depends on input text, but i still dont understand why this is non sence, it should create div with text in it Quote Link to comment https://forums.phpfreaks.com/topic/162120-jquery-post-and-use-the-return/#findComment-855600 Share on other sites More sharing options...
RichardRotterdam Posted June 14, 2009 Share Posted June 14, 2009 it should print "account created", depends on input text, but i still dont understand why this is non sence, it should create div with text in it The $() function in jQuery is the selector function which returns a single element or a collection of DOM elements it doesn't create a new element. http://docs.jquery.com/Selectors You can place <div id="register_respond"></div> in your html. That or use the jquery add function() , html() function or anything else to add html dynamicly Quote Link to comment https://forums.phpfreaks.com/topic/162120-jquery-post-and-use-the-return/#findComment-855609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.