Possible duplicate: jquery change div text
The above question is a possible duplicate, but I don’t know why it doesn’t work. I’m fairly new to jQuery as well.
Below is part of the function (all I have written right now). It’s being triggered with an onclick event for an anchor tag.
function changeStatus(user)
{
var esc = true;
$.get('ajax/popupBase.html', user, function(data, stat, d) {
$("#AjaxFrame").html(data);
}, 'html');
$.get('ajax/changeStatus.html', user, function(data, stat, d) {
$("#PopupBody").html(data);
}, 'html');
$("#AjaxFrame").fadeIn('fast');
$("#PopupTitle").html("Status Update");
$("#Popup").center();
popupState = 1;
return esc;
}
Here is the template “popupBase.html” that I’m using with $.get():
Note: “popupBase.html” is a reproducible “popup” window that I have on this site and I can just insert data into the empty divs, and re-use html where possible
<div id="Popup">
<form id="Popup1" method="post">
<div id="PopupTitle"></div>
<div id="PopupBody"></div>
<input class="button" id="Save" name="saveChanges" type="submit" value="OK" />
<input class="button" id="Cancel" name="clearChanges" type="button" value="Cancel" />
</form>
</div>
The #AjaxFrame is a container just outside all html on my site (inside <body>, outside #Wrapper). I also have two empty containers on my template from my $.get() call, called #PopupTitle and #PopupBody.
Question: Inserting the html retrieved from “changeStatus.html” into #PopupBody works fine, however, adding static text from #PopupTitle doesn’t work. In this possible duplicate‘s answer, I tried using .text() to no avail.
EDIT: A note for future readers, I am clearing the contents of the #AjaxFrame after each use which should renew the ID usage.
Other things I’ve tried: clearing Chrome’s cache (both latest and portableapp version) and checking for typos over and over.
I’m realllly confused about this, any help is appreciated.
Your running into a race condition, javascript isn’t going to wait for those $.get functions to complete before running what happens after it.
If you want “Status Update” to be in PopupTitle AFTER your ajax gets have run their course, it has to go in the success handler