473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Issues with IE & Prototype/AJAX

The following code works great in FireFox, Opera, Netscape, Safari, and
Gecko, but NOT IE. Why?

I tried using 'native' js with setInterval and setTimeout, but I get
the same result. My IE security settings are not an issue.

Anyone have any insight on this?

Thanks!
-sh
************************************************** ***************
// JavaScript Document
var ud1 = new PeriodicalExecuter(getIncrementer, 5);
var ud2 = new PeriodicalExecuter(getMicrotime, 5);

function getIncrementer()
{
var url = 'filter.htm';
var myAjax = new Ajax.Request( url, { method: 'get', onComplete:
showMyData });
}

function getMicrotime()
{
var url = 'filter2.htm';
var myAjax2 = new Ajax.Request( url, { method: 'get', onComplete:
showMicrotime });
}

function showMyData(req)
{
//put returned Text/XML in the textarea
$('my_div').innerHTML = req.responseText;
}

function showMicrotime(req)
{
//put returned Text/XML in the textarea
$('microtime_div').innerHTML = req.responseText;
}

Aug 2 '06 #1
17 3106

Steve-O wrote:
The following code works great in FireFox, Opera, Netscape, Safari, and
Gecko, but NOT IE. Why?
For some udisclosed value of 'works' and 'not (works)'.

I tried using 'native' js with setInterval and setTimeout, but I get
the same result. My IE security settings are not an issue.
prototype.js is about 1,800 lines of code and you give no hints as to
where the error might be. Post the 'native' js version and you might
get an answer - or ask in a prototype.js news group or forum.

[...]
--
Rob

Aug 3 '06 #2
Steve-O wrote:
The following code works great in FireFox, Opera, Netscape, Safari, and
Gecko, but NOT IE. Why?

I tried using 'native' js with setInterval and setTimeout, but I get
the same result. My IE security settings are not an issue.

Anyone have any insight on this?

Thanks!
-sh
************************************************** ***************
// JavaScript Document
var ud1 = new PeriodicalExecuter(getIncrementer, 5);
var ud2 = new PeriodicalExecuter(getMicrotime, 5);

function getIncrementer()
{
var url = 'filter.htm';
var myAjax = new Ajax.Request( url, { method: 'get', onComplete:
showMyData });
}

function getMicrotime()
{
var url = 'filter2.htm';
var myAjax2 = new Ajax.Request( url, { method: 'get', onComplete:
showMicrotime });
}

function showMyData(req)
{
//put returned Text/XML in the textarea
$('my_div').innerHTML = req.responseText;
}

function showMicrotime(req)
{
//put returned Text/XML in the textarea
$('microtime_div').innerHTML = req.responseText;
}
setTimeout sometimes catches me because I forget that they are separate
threads and that they only run once. If you want to make a sort of
do-events style for-loop type structure using setTimeout instead, you
need two functions.

The first starts it going, eg:
<scriptsetTimeout(code, time); </script>

the second has to decide whether to set it going again:
<script>
DoStuff()
if (keepgoing) setTimeout(code, time);
</script>

careful that you keep track of if the loops is current executing, eg
with a global variable or something more refined. Else someone might
start the timer twice and you'll get two loops that each spawn two new
ones when they finish. Generally doubles the framerate of whatever you
are updating, but not in a good way.

hth

http://darwinist.googlepages.com/htmldesktop.html

Aug 3 '06 #3
da*******@gmail.com wrote:
<snip>
... I forget that they are separate threads ...
You should as javascript is not multithreaded, so they are _not_
separate threads.

Richard.
Aug 3 '06 #4
Ray

Richard Cornford wrote:
da*******@gmail.com wrote:
<snip>
... I forget that they are separate threads ...

You should as javascript is not multithreaded, so they are _not_
separate threads.
When you send an AJAX request using Prototype, isn't it done using a
separate thread? I know what you mean about JS (the language) being not
multithreaded though.
>
Richard.
Aug 3 '06 #5
Ray wrote:
Richard Cornford wrote:
>da*******@gmail.com wrote:
<snip>
>>... I forget that they are separate threads ...

You should as javascript is not multithreaded, so they are _not_
separate threads.

When you send an AJAX request using Prototype, isn't it done using a
separate thread?
I would never use Protoytpe.js, I know javascript. The XML HTTP request
objects (at least when making asynchronous requests) must be operating
in what is effectively a separate thread (but they are likely written
in C++). The handling of the response by javascript is not
multithreaded; no executing javascript in the same environment will be
interrupted by/overlap with the response from and XML HTTP request
object and the handling of that response will not be interrupted
by/overlap with event handling code or setTimeout/Interval triggered
code (the latter must wait until the handling of the XML HTTP response
comes to an end).
I know what you mean about JS (the language) being not
multithreaded though.
Good, VK is likely to try to make out the javascript is multithreaded
(at least he has often done so in the past) but nobody else is that
foolish.

Richard.

Aug 3 '06 #6
Ray
Richard Cornford wrote:
<snip>
The handling of the response by javascript is not
multithreaded; no executing javascript in the same environment will be
interrupted by/overlap with the response from and XML HTTP request
object and the handling of that response will not be interrupted
by/overlap with event handling code or setTimeout/Interval triggered
code (the latter must wait until the handling of the XML HTTP response
comes to an end).
Ah, I didn't know this part. Thanks! That's good to know.

<snip>

Aug 3 '06 #7
Ray
Richard Cornford wrote:
I would never use Protoytpe.js, I know javascript. <snip>
What's wrong with Prototype? What do you think of other libraries like
Dojo toolkit or X ?

Thanks,
Ray
Richard.
Aug 3 '06 #8
On 03/08/2006 12:05, Ray wrote:
Richard Cornford wrote:
>I would never use Protoytpe.js, I know javascript. <snip>

What's wrong with Prototype?
There has been at least one thread dedicated to criticism of the
Prototype library[1]. Feel free to browse the archives[2]. :-)
What do you think of other libraries like Dojo toolkit or X ?
I'm not trying to speak for Richard, but his answer is highly likely to
be negative; he dislikes monolithic libraries, as do some other regulars
in this group. You will quickly realise that from browsing the
archives[3]. Perhaps he has specific criticism, though.

I've never used any of them, myself, and only glanced at Prototype long
enough to dislike it.

Mike
[1] prototype.js criticism 2006-03-20 07:26:45 GMT
<11*********************@g10g2000cwb.googlegroups. com>
<http://groups.google.co.uk/group/comp.lang.javascript/browse_thread/thread/b699522a97d26a6d/5d5110a25cd79c2e?lnk=st&q=&rnum=2&hl=en#5d5110a25c d79c2e>

[2] Google Groups search results for:
group:comp.lang.javascript prototype library wrong | bad | evil
<http://groups.google.co.uk/groups?lnk=hpsg&hl=en&q=group%3Acomp.lang.javascri pt+prototype+library+wrong+%7C+bad+%7C+evil>

[3] Google Groups search results for:
group:comp.lang.javascript author:"Richard Cornford" libraries
<http://groups.google.co.uk/groups/search?hl=en&q=group%3Acomp.lang.javascript+author %3A%22Richard+Cornford%22+libraries&qt_s=Search>
Aug 3 '06 #9
Ray

Michael Winter wrote:
On 03/08/2006 12:05, Ray wrote:
Richard Cornford wrote:
>
I would never use Protoytpe.js, I know javascript. <snip>
What's wrong with Prototype?

There has been at least one thread dedicated to criticism of the
Prototype library[1]. Feel free to browse the archives[2]. :-)
<snip>

Thanks Michael!! That's going to be educational for me :)

Cheers
Ray

Aug 3 '06 #10
Ray wrote:
Richard Cornford wrote:
>I would never use Protoytpe.js, I know javascript.
<snip>
What's wrong with Prototype?
It would take too long to explain properly, but it appears to mostly
come down to the authors not really knowing javascript well enough to
appreciate it as a language and instead trying to twist it into
something more like a language that they did appreciate. There is a
Catch 22 in that attitude, in that they would have had to learn to
appreciate javascript before being in a position to do a good job
twisting it to be like their preferred language, at which point they
would no longer have seen a need to make the effort. The inevitable
result of this contradiction is a large collection of interdependent,
brittle, environment limited, inefficient and bulky code.
What do you think of other libraries like
Dojo toolkit or X ?
Libraries are mostly about code re-use, but as a strategy for code
re-use they do not fit well with the nature of browser scripting.
Alternative strategies offer equivalent levels or code re-use (or
better) and are better suited to the necessity of having all the
executable code used downloaded to the browser.

Richard.
Aug 3 '06 #11
Richard Cornford wrote:
da*******@gmail.com wrote:
<snip>
... I forget that they are separate threads ...

You should as javascript is not multithreaded, so they are _not_
separate threads.
What is it then when you fire one or more setTimeout() calls? They
behaves very differently to just continuing with code (other events
will occur, such as a display refresh, for example) and you can have it
fire on user-events, generating multiple timing loops occuring at once.
What is this if not threads?
Richard.
Aug 4 '06 #12

da*******@gmail.com wrote:
Richard Cornford wrote:
da*******@gmail.com wrote:
<snip>
... I forget that they are separate threads ...
You should as javascript is not multithreaded, so they are _not_
separate threads.

What is it then when you fire one or more setTimeout() calls? They
behaves very differently to just continuing with code (other events
will occur, such as a display refresh, for example) and you can have it
fire on user-events, generating multiple timing loops occuring at once.
What is this if not threads?
A queue.

The browser itself may be multi-threaded and most seem to be - they can
fire many HTTP requests and download various parts of a document
simultaneously. The script element's 'defer' attribute seems to have
been inspired by this behaviour, allowing a browser to download other
resources while downloading and executing the script.

Most browsers will not update the screen while a script is running,
which makes sense - why constantly update the screen while DOM
manipulation is occurring? It makes much more sense to wait until all
modifications have occurred and then re-paint the screen once.

In JavaScript, only one thread runs at a time. It has already been
categorically stated in this thread that one JavaScript process can't
interrupt another, therefore neither setTimeout or setInterval can
interrupt an executing process - they must wait until whatever process
is running completes before they run. Otherwise it would be very
simple to use setTimeout to stop an endless loop, e.g.:

var _gobal = this;
function stopProcess(process) {
setTimeout(function() _global[process] = null;}, 1000)
}
function endlessLoop() {
stopProcess(arguments.callee.name);
while(true){}
}

If the above did work (and I guarantee it doesn't) then stopProcess()
should be able to cancel the endless loop - but it can't because as
long as endlessLoop() runs, no other script will get a look-in. If it
were possible, I imagine it would be used extensively in debugging.

Of course the *browser* may (and some do) provide another thread that
monitors and optionally cancels a an executing JavaScript process, but
that is a host environment thread, not a second (or third or fourth)
JavaScript thread.
--
Rob

Aug 4 '06 #13
Ray

Richard Cornford wrote:
<snip>
What do you think of other libraries like
Dojo toolkit or X ?

Libraries are mostly about code re-use, but as a strategy for code
re-use they do not fit well with the nature of browser scripting.
Alternative strategies offer equivalent levels or code re-use (or
better) and are better suited to the necessity of having all the
executable code used downloaded to the browser.
Thanks Richard,

Wondering what the alternative strategies to code reuse are, if not
libraries? The moment you separate your oft-used code into a separate
js file and organize them into functions/classes, you have a library,
don't you?

Regards,
Ray
>
Richard.
Aug 4 '06 #14
RobG wrote:
da*******@gmail.com wrote:
Richard Cornford wrote:
da*******@gmail.com wrote:
<snip>
... I forget that they are separate threads ...
>
You should as javascript is not multithreaded, so they are _not_
separate threads.
What is it then when you fire one or more setTimeout() calls? They
behaves very differently to just continuing with code (other events
will occur, such as a display refresh, for example) and you can have it
fire on user-events, generating multiple timing loops occuring at once.
What is this if not threads?

A queue.

The browser itself may be multi-threaded and most seem to be - they can
fire many HTTP requests and download various parts of a document
simultaneously. The script element's 'defer' attribute seems to have
been inspired by this behaviour, allowing a browser to download other
resources while downloading and executing the script.

Most browsers will not update the screen while a script is running,
which makes sense - why constantly update the screen while DOM
manipulation is occurring? It makes much more sense to wait until all
modifications have occurred and then re-paint the screen once.

In JavaScript, only one thread runs at a time. It has already been
categorically stated in this thread that one JavaScript process can't
interrupt another, therefore neither setTimeout or setInterval can
interrupt an executing process - they must wait until whatever process
is running completes before they run. Otherwise it would be very
simple to use setTimeout to stop an endless loop, e.g.:

var _gobal = this;
function stopProcess(process) {
setTimeout(function() _global[process] = null;}, 1000)
}
function endlessLoop() {
stopProcess(arguments.callee.name);
while(true){}
}

If the above did work (and I guarantee it doesn't) then stopProcess()
should be able to cancel the endless loop - but it can't because as
long as endlessLoop() runs, no other script will get a look-in. If it
were possible, I imagine it would be used extensively in debugging.

Of course the *browser* may (and some do) provide another thread that
monitors and optionally cancels a an executing JavaScript process, but
that is a host environment thread, not a second (or third or fourth)
JavaScript thread.
How very interesting. I had to write my own infinite loop examples to
understand what you mean, but see how it distinguishes a queue from the
thread. Thanks for the info.

For many practical purposes, you can have the equivalent of multiple
loops running at once, with the gui still responsive while they're
running, using timeouts.

---
http://darwinist.googlepages.com/htmldesktop.html
(A free, open-source web-based IDE, windowing system, and desktop
environment, in 31kB of html and javascript.)
>
--
Rob
Aug 4 '06 #15
Ray wrote:
Wondering what the alternative strategies to code reuse are, if not
libraries? The moment you separate your oft-used code into a separate
js file and organize them into functions/classes, you have a library,
don't you?
Search the google archives of this group for "cornford libraries" and you'll
find many debates on the topic, often with me ;)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Aug 4 '06 #16
Ray
Thanks Matt!! Will do the search you recommended as well.

Cheers
Ray

Matt Kruse wrote:
Ray wrote:
What's wrong with Prototype?

http://www.javascripttoolbox.com/bes...ces/#prototype

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Aug 4 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: k.mitz | last post by:
Hi, I have a PHP application that allows users to generate a .pdf report of their database content. Normally, I've had to refresh a page to call the script to generate the report, so there's a...
3
by: morganwhitney | last post by:
Hi all, I am developing a web app and I am implementing the JavaScript using the Prototype Framework. I have done all the same stuff from scratch in a previous application and it worked fine, but...
10
by: Steve | last post by:
I need to build a very dynamic client and would be interested in knowing the pros and cons of using JSF and Ajax to accomplish this. Thanks. Steve
1
by: vachacz | last post by:
hi i'm struggling with integration of a js class aimed for ajax handling with fireing actions from the class. here's my code sample: function AjaxLibLoad(httpActionParam, targetLayerParam){...
5
by: dougwig | last post by:
I'm trying to handle the scenario where a user's session times out and and their ajax request triggers a redirection by the webserver (302 error?). I'm using Prototype 1.4 and the my works great...
7
by: BeeRich | last post by:
Hi folks. I built an ajax.updater reply in a website on a Mac, and she works fine. It's a simple reply, the html supplied is correct, and I also supply the target DIV as well. Just wondering...
5
by: Gerry Vandermaesen | last post by:
Hi, Does anyone have a freely available JavaScript JSON stringifier. So far my search has been in vain, the one offered on http://www.json.org/json.js does not seem to work for me.
23
by: Dautkhanov | last post by:
Hello ! Does anybody have cutted version of prototype.js with the AJAX functionality only? I am a new in prototype.js topic, so I think this task should be done by other developers. Maybe...
3
by: jacobstr | last post by:
I've noticed Object.extend used in a few different ways and I'm having trouble distinguishing why certain usages apply to a given situation. On line 804 Ajax.Base is defined as follows: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.