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 showAl开发者_高级运维l() 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();
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/
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.
精彩评论