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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.