Jump to content

jQuery POST and use the return


godsent

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/162120-jquery-post-and-use-the-return/
Share on other sites

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.