d.mc2
d.mc2

Reputation: 1129

Make something live in JQuery

I have in my Document Ready:

$(document).ready(function () {       
    showAll();
    var av= $('#a').attr('value');
alert(av);                              <-----**Debugging Value**
    if(av == 1) { 
         alert("1")  
     } else {
         alert("0")
     }
 });

The function showAll() calls a PHP and directly generates hidden inputs.

<input type='hidden' value='///automatically generated 1 or 0///'>

My probelm right now is when I alert av at the Debugging Value, it is undefined. And I know this is because that section is not live. How can I make that section live automatically. If i used live('click', etc etc....) then that works, but I am trying to make it load based on the conditional.

Thanks for your help.

EDIT:///

My showProf looks like this:

xmlhttp.onreadystatechange=function()         {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("id_verified").innerHTML=xmlhttp.responseText;
        }
      }

xmlhttp.open("GET","showProf.php?i="+myi+"&t=" + Math.random(),true);
xmlhttp.send();

Upvotes: 0

Views: 90

Answers (2)

jack
jack

Reputation: 1317

You can do a callback from your ajax call like

$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});

From http://api.jquery.com/jQuery.ajax/

Upvotes: 2

jfriend00
jfriend00

Reputation: 707318

If showAll is making an asynchronous ajax call (which I'm assuming since you said it's a PHP call), then the ajax call has probably not completed yet. For asynchronous ajax calls, you have to hook the completion callback and do any work after the ajax call from the completion callback function.

Calling an ajax call just starts the call and then your javascript execution continues while the ajax call operates. That means your debugging statement is happening right after the ajax call has started, not after it's completed.

Upvotes: 1

Related Questions