Jump to content

onreadystatechange within a function


ted_chou12

Recommended Posts

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 :P)

Thanks,

Ted

Link to comment
https://forums.phpfreaks.com/topic/163325-onreadystatechange-within-a-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.