ted_chou12 Posted June 23, 2009 Share Posted June 23, 2009 Hi, below are part of my code, but there is something that i don't quite understand: //ajax initial variables... //codes: function ajaxphotocmt(vari) {ajax_request.onreadystatechange = function() {//Call a function when the state changes. if(ajax_request.readyState == 4) {stringarray = ajax_request.responseText.split(";seDp#"); photocomment.title.value = stringarray[0]; alert(); photocomment.message.innerHTML = stringarray[1];}} varis = vari.split(";"); if (varis[0] == "edit") { ajax_request.open("GET", "../admin/ajaxvars.php?ajaxvar=photocommentedit&id=" + varis[1], true); ajax_request.send(null);}} The code works in this order, but not the other way: //ajax initial variables... //codes: function ajaxphotocmt(vari) { varis = vari.split(";"); if (varis[0] == "edit") {ajax_request.onreadystatechange = function() {//Call a function when the state changes. if(ajax_request.readyState == 4) {stringarray = ajax_request.responseText.split(";seDp#"); photocomment.title.value = stringarray[0]; alert(); photocomment.message.innerHTML = stringarray[1];}} ajax_request.open("GET", "../admin/ajaxvars.php?ajaxvar=photocommentedit&id=" + varis[1], true); ajax_request.send(null);}} Can someone please explain to me what is the reason behind it (I am a new to ajax, so i may not know some of the technical things ) Thanks, Ted Link to comment https://forums.phpfreaks.com/topic/163325-onreadystatechange-within-a-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.