Ajax is not asynchronous

  • Thread starter Rex the Strange
  • Start date
R

Rex the Strange

Seriously.

I have a flash animation that I was trying to run during ajax calls -
sort of eyecandy - but it would freeze whenever the ajax call was
being made. Then I found out it wasn't just the flash, it was the
entire page - could scroll, type, do jack.

Asynchronous javascript? Yeah, right. (and before you suggest it, that
isAscync parameter in the open function doesn't seem to do jack unless
I'm not using a boolean correctly)

</sarcasm>
 
J

Joost Diepenmaat

Rex the Strange said:
Asynchronous javascript? Yeah, right. (and before you suggest it, that
isAscync parameter in the open function doesn't seem to do jack unless
I'm not using a boolean correctly)

</sarcasm>

Nice sarcasm. Show the code.
 
R

Rex the Strange

Nice sarcasm. Show the code.

Gladly:

/**********/

function ajax_object (callback_field) {
var request_object;
var callback = document.getElementById (callback_field);
var eyecandy = document.getElementById ("flash_cell");
var parameters = new ajax_parameters;

request_object = ajax_object ();

/********/

function show_eyecandy () {
callback.innerHTML = blank;
eyecandy.style ["visibility"] = "visible";
}// show_eyecandy;

/********/

function hide_eyecandy () {
callback.style ["visibility"] = "visible";
eyecandy.style ["visibility"] = "hidden";
}// hide_eyecandy;

/********/

function ajax_object () {
var object;
try {
object = new XMLHttpRequest ();
} catch (except) {
try {
object = new ActiveXObject ("Msxml2.XMLHTTP");
} catch (except) {
try {
object = new ActiveXObject ("Microsoft.XMLHTTP");
} catch (except) {
return false;
}// try
}// try
}// try
return object;
}// ajax_object;

/********/

this.add_parameters = function (name, value) {
parameters.add (name, value);
}// add_parameters;

/********/

this.callback_function = function (data) {
if (request_object.readyState != 4) return;
callback.innerHTML = request_object.responseText;
hide_eyecandy ();
}// callback_function;

/********/

this.send = function (destination) {
show_eyecandy ();
request_object.onreadystatechange = this.callback_function;
request_object.open ("post", destination, true);
request_object.setRequestHeader ("Content-Type", "application/x-www-
form-urlencoded; charset=UTF-8");
request_object.send (parameters.render ());
}// this.send;

/********/

}// ajax_object;

/**********/

function ajax_parameters () {
var items = [];

this.add = function (name, value) {
items.push (name + "=" + value);
}// add;

this.render = function () {
return items.join ("&");
}// render;
}// ajax_parameters;

/**********/
 
R

Rex the Strange

Nice sarcasm. Show the code.

Gladly:

/**********/

function ajax_object (callback_field) {
        var request_object;
        var callback = document.getElementById (callback_field);
        var eyecandy = document.getElementById ("flash_cell");
        var parameters = new ajax_parameters;

        request_object = ajax_object ();

        /********/

        function show_eyecandy () {
                callback.innerHTML = blank;
                eyecandy.style ["visibility"] = "visible";
        }// show_eyecandy;

        /********/

        function hide_eyecandy () {
                callback.style ["visibility"] = "visible";
                eyecandy.style ["visibility"] = "hidden";
        }// hide_eyecandy;

        /********/

        function ajax_object () {
                var object;
                try {
                        object = new XMLHttpRequest ();
                } catch (except) {
                        try {
                                object =new ActiveXObject ("Msxml2.XMLHTTP");
                        } catch (except) {
                                try {
                                        object = new ActiveXObject ("Microsoft.XMLHTTP");
                                } catch (except) {
                                        return false;
                                }// try
                        }// try
                }// try
                return object;
        }// ajax_object;

        /********/

        this.add_parameters = function (name, value) {
                parameters.add (name, value);
        }// add_parameters;

        /********/

        this.callback_function = function (data) {
                if (request_object.readyState != 4) return;
                callback.innerHTML = request_object.responseText;
                hide_eyecandy ();
        }// callback_function;

        /********/

        this.send = function (destination) {
                show_eyecandy ();
                request_object.onreadystatechange = this..callback_function;
                request_object.open ("post", destination, true);
                request_object.setRequestHeader ("Content-Type", "application/x-www-
form-urlencoded; charset=UTF-8");
                request_object.send (parameters.render ());
        }// this.send;

        /********/

}// ajax_object;

/**********/

function ajax_parameters () {
        var items = [];

        this.add = function (name, value) {
                items.push (name + "=" + value);
        }// add;

        this.render = function () {
                return items.join ("&");
        }// render;

}// ajax_parameters;

/**********/

Well, I've shown the code. What am I doing wrong?
 
V

VK

function ajax_object (callback_field) {
var request_object;
var callback = document.getElementById (callback_field);
var eyecandy = document.getElementById ("flash_cell");
var parameters = new ajax_parameters;
request_object = ajax_object ();
/********/

function show_eyecandy () {
callback.innerHTML = blank;
eyecandy.style ["visibility"] = "visible";
}// show_eyecandy;
/********/

function hide_eyecandy () {
callback.style ["visibility"] = "visible";
eyecandy.style ["visibility"] = "hidden";
}// hide_eyecandy;
/********/

function ajax_object () {
var object;
try {
object = new XMLHttpRequest ();
} catch (except) {
try {
object = new ActiveXObject ("Msxml2.XMLHTTP");
} catch (except) {
try {
object = new ActiveXObject ("Microsoft.XMLHTTP");
} catch (except) {
return false;
}// try
}// try
}// try
return object;
}// ajax_object;
/********/

this.add_parameters = function (name, value) {
parameters.add (name, value);
}// add_parameters;
/********/

this.callback_function = function (data) {
if (request_object.readyState != 4) return;
callback.innerHTML = request_object.responseText;
hide_eyecandy ();
}// callback_function;
/********/

this.send = function (destination) {
show_eyecandy ();
request_object.onreadystatechange = this.callback_function;
request_object.open ("post", destination, true);
request_object.setRequestHeader ("Content-Type", "application/x-www-
form-urlencoded; charset=UTF-8");
request_object.send (parameters.render ());
}// this.send;
/********/

}// ajax_object;
/**********/

function ajax_parameters () {
var items = [];
this.add = function (name, value) {
items.push (name + "=" + value);
}// add;
this.render = function () {
return items.join ("&");
}// render;
}// ajax_parameters;
/**********/

Well, I've shown the code. What am I doing wrong?

That was answered N times in this group: the graphics context is not
being updated until exit from the current execution context. With your
nested functions - besides being memory leaking like an old bucket -
you never give this opportunity to the engine. use setTimeout at
least.
 
J

Joost Diepenmaat

Ok ok, I didn't reply to your code the first time, because I couldn't
find the error. Though the naming of some of the variables did make my
head hurt. Here's what I've got.

callbacks are usually functions.

I note that you're calling a nested ajax_object() function within this
ajax_object() function. Also the outer function *seems* to be a
constructor, while the inner function isn't. Can't see how you're
calling the outer function, though.

Does this mean you've left some code out here?
        function show_eyecandy () {
                callback.innerHTML = blank;
                eyecandy.style ["visibility"] = "visible";

this is probably better (or at least, shorter) written as

eyecandy.style.visibilitiy = "visible";
        }// show_eyecandy;


        /********/

        function hide_eyecandy () {
                callback.style ["visibility"] = "visible";
                eyecandy.style ["visibility"] = "hidden";

same here.
        }// hide_eyecandy;

        /********/

        function ajax_object () {
                var object;
                try {
                        object = new XMLHttpRequest ();
                } catch (except) {
                        try {
                                object = new ActiveXObject ("Msxml2.XMLHTTP");
                        } catch (except) {
                                try {
                                        object = new ActiveXObject ("Microsoft.XMLHTTP");
                                } catch (except) {
                                        return false;
                                }// try
                        }// try
                }// try
                return object;
        }// ajax_object;

        /********/

        this.add_parameters = function (name, value) {
                parameters.add (name, value);
        }// add_parameters;

        /********/

        this.callback_function = function (data) {
                if (request_object.readyState != 4) return;
                callback.innerHTML = request_object.responseText;
                hide_eyecandy ();
        }// callback_function;

        /********/

        this.send = function (destination) {
                show_eyecandy ();
                request_object.onreadystatechange = this.callback_function;
                request_object.open ("post", destination, true);
                request_object.setRequestHeader ("Content-Type", "application/x-www-
form-urlencoded; charset=UTF-8");
                request_object.send (parameters.render ());
        }// this.send;

        /********/

}// ajax_object;

/**********/

function ajax_parameters () {
        var items = [];

        this.add = function (name, value) {
                items.push (name + "=" + value);
        }// add;

        this.render = function () {
                return items.join ("&");
        }// render;

this will break if your names or values contain any characters that need to
be urlencoded.
Well, I've shown the code. What am I doing wrong?

Dunno. Got a URL?

Joost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,794
Messages
2,569,641
Members
45,354
Latest member
OrenKrause

Latest Threads

Top