I receive a JSON-File via ajax and added it to my DOM (see: how to read information of an ajax-dialogbox)
Now i wanted to get access to this DOM-node, but the only way it worked was:
get_ajax_dialogwindow();
alert("wait for click");
alert("Test Combo" + combobox_by_name(value.ID_of_name));
this worked perfectly fine, but I don't want the user to click first. If I try only
get_ajax_dialogwindow();
alert("Test Combo" + combobox_by_name(value.ID_of_name));
I only get empty space where the data should be... I guess it's because the DOM isn't ready again. I tried $(document).ready, setTimeout, .delay(), ajax.stop, DOMContentReady but the only thing that worked was a simple alert("wait"); but i can't live with that solution because I don't want the user to click 20 times :P
any ideas?
Thank you! :)
Edit:
here is the code:
function combobox_by_name(ID_of_name){
return $('select[name=audience\\[' + ID_of_name + '\\]\\[value\\]] option:selected').text();
}
and the ajax call I do right before the alert with the insert of the HTML-node:
function get_ajax_dialogwindow(){
var data = '__a=1&__d=1&__user='+get_userID(); //Parameter für den Ajax Aufruf. Bestehend aus __a=1, __d=1 und der UserID
var json;
$.ajax({
type:"GET",
url: get_ajax_url(), //url für empfänger des Ajax Aufrufs. Lässt sich mit Firebug herausfinden, wenn man den link der das Dialogfenster öffnet analysiert
data: data,
dataType: "text", //eigentlich ist es json und kein text, allerdings gibt es einen Schutz von Facebook,
//der die Dauerschleife for(;;;) vorne heranschiebt. Deshalb wird es als Text betrachtet
success: function(response) {
response = response.replace(/.*?;{/, "{"); //Entfernt for(;;;)
jsonFile = JSON.parse(response); //Parsed den Text in ein Json file
$('#globalContainer').append(jsonFile.payload.body.__html); //Fügt das Dialogfenster ganz unten an die Seite hinzu
},
error: function(xhr) { //Fehlermeldung, falls der Ajax aufruf fehlschlägt
alert('Error! Status = ' + xhr.status);
alert(xhr.responseText);
}
});
}