By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,686 Members | 1,603 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

Ajax Timeouts

P: n/a
Hi I need help with prototype while doing ajax calls. So this is my JS
which does a ajax calls

var ajax1 = new Ajax.Request (
url,
{
method: 'get',
parameters: params,
onComplete: showResults,
onFailure: showFailure
}
);

this calls works fine but i need to know how I can set a timeout saying
after 5 seconds you should give up and show a message to the user how
can this be achieved. I want to achieve this without changing any code
in prototype.js

Does any one have knowledge in using prototype.js to its best, I looked
at this article http://www.sergiopereira.com/articles/prototype.js.html
does anyone know if there is a official documentation for the library.

Last is there a freebie library better than prototype.js

Thank you
C

May 23 '06 #1
Share this Question
Share on Google+
17 Replies


P: n/a
Chaprasi wrote:
Hi I need help with prototype while doing ajax calls. So this is my
JS which does a ajax calls
Prototype.js is generally avoided by most people in this group.
You won't find much help for it here.
this calls works fine but i need to know how I can set a timeout
saying after 5 seconds you should give up and show a message to the
user how can this be achieved.
I don't know if prototype supports timeouts, but my AjaxRequest library
does:
http://www.ajaxtoolbox.com/request/examples.php
does anyone
know if there is a official documentation for the library.
Part of the issue with prototype.js is that the documentation is almost
non-existent and there doesn't seem to be a good support system for the
library. So users end up coming here, for example, which is annoying.
Last is there a freebie library better than prototype.js


Yes. Many :)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 23 '06 #2

P: n/a
Thank you for the response. I know I implemeted prototype.js but I am
open to nice JS libraries which does all the wrapping for doing ajax.

So can you name a few of these libraries which are better than
prototype.

Thanks
C

May 23 '06 #3

P: n/a
Chaprasi said the following on 5/23/2006 3:16 PM:
Thank you for the response.
Thank you for quoting what you are replying to in the future.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
<URL: http://www.safalra.com/special/googlegroupsreply/ >
I know I implemeted prototype.js but I am open to nice JS libraries
which does all the wrapping for doing ajax.

So can you name a few of these libraries which are better than
prototype.


*Any* library is better than prototype.

<URL: http://www.ajaxtoolbox.com/>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 23 '06 #4

P: n/a
Matt Kruse wrote:
Chaprasi wrote:
Hi I need help with prototype while doing ajax calls. So this is my
JS which does a ajax calls

Prototype.js is generally avoided by most people in this group.
You won't find much help for it here.


I haven't really looked at prototype.js - would you mind sharing why
it's generally avoided?
May 23 '06 #5

P: n/a
I am not trying to avoid it, I just was thinking if there are better
libraries who can give me handle over timeouts, onerrors.

So far AjaxRequest looks good which is available at
http://www.ajaxtoolbox.com/

Tony wrote:
Matt Kruse wrote:
Chaprasi wrote:
Hi I need help with prototype while doing ajax calls. So this is my
JS which does a ajax calls

Prototype.js is generally avoided by most people in this group.
You won't find much help for it here.


I haven't really looked at prototype.js - would you mind sharing why
it's generally avoided?


May 23 '06 #6

P: n/a
Tony wrote:
Matt Kruse wrote:
Chaprasi wrote:
Hi I need help with prototype while doing ajax calls. So this is my
JS which does a ajax calls

Prototype.js is generally avoided by most people in this group.
You won't find much help for it here.


I haven't really looked at prototype.js - would you mind sharing why
it's generally avoided?


In no particular order:

1. It modifies the protoype of some built-in objects so that
using say, for..in with an array object produces unexpected results.
2. It requires a different syntax, so that instead of using say:

var el = document.getElementById('someID');

you use:

var el = $('someID');

Instead of looping through a number of IDs, you'd use:

var els = $('someID_01', 'someID_02', elRef_03);
3. Having used and become dependent on its syntax, you'll
have to learn 'real' JavaScript at some point.
4. It is utterly undocumented by the author and only very
sparsely commented. Some other attempts at documentation:

<URL:http://blogs.ebusiness-apps.com/jordan/pages/Prototype%20Library%20Info.htm>
<URL:http://www.sergiopereira.com/articles/prototype.js.html>
<URL:http://wiki.script.aculo.us/scriptaculous/show/Prototype>
<URL:http://www.snook.ca/archives/000531.php>
5. There is no support community or blog of any real substance
6. It has about 2,0000 lines of code when only a small subset
might be needed. It is not easy to use only portions,
as many functions are reliant on others. Those dependencies
are not documented.
7. Its feature detection is sparse and it is likely to fail in
many browsers with no chance of recovery
8. It encourages bad coding practice with functions like:

Try.these( func01(...), func02(...), func03(...) );

as a shortcut for multiple try..catch blocks and replacement
for feature detection.

And so on...
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
May 24 '06 #7

P: n/a
I'm not particularly pro prototype.js but

RobG wrote:
prototype.js
1. It modifies the protoype of some built-in objects so that
using say, for..in with an array object produces unexpected results.


Is the for..in loop problem still a problem or is that something they
have fixed?

5. There is no support community or blog of any real substance


It is possible to try on the rails spinoff list.
-Peter

May 24 '06 #8

P: n/a
pe**********@gmail.com wrote:
I'm not particularly pro prototype.js but

RobG wrote:
prototype.js

1. It modifies the protoype of some built-in objects so that
using say, for..in with an array object produces unexpected results.


Is the for..in loop problem still a problem or is that something they
have fixed?


The official latest version is 1.4, I tested it with 1.5.0_rc0 (see 1.
below). Yes, it's still a problem and likely always will be.

The issue stems from the fact that prototype.js modifies the prototype
of the in-built Array object. The same functionality could have been
achieved by creating a special prototype.js array object (say called
PTArray or _$A or whatever) and modifying that, but that's not how the
author chose to do it.
1. There are 31 extra properties:

each, all, any, collect, detect, findAll, grep, include,
inject, invoke, max, min, partition, pluck, reject, sortBy,
toArray, zip, inspect, find, select, member, entries, _reverse,
_each, clear, first, last, compact, flatten, without
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
May 24 '06 #9

P: n/a
RobG wrote:
<snip>
2. It requires a different syntax, so that instead of
using say:

var el = document.getElementById('someID');

you use:

var el = $('someID');

<snip>

That is also function name chosen with a disregard for the convention
laid out in the ECMAScript specification where all Identifiers beginning
with '$' are intended it indicate machine generated Identifiers. No
reasonable javascript code should be written without a regard for that
obviously well known/understood convention.

Richard.
May 24 '06 #10

P: n/a
RobG wrote:
Tony wrote:
I haven't really looked at prototype.js - would you mind sharing why
it's generally avoided?


In no particular order:


<list of pretty bad stuff>

Ouch - I can understand why it's not well-liked here.
May 24 '06 #11

P: n/a
Guys now I am using AjaxRequest library and the timeout does not work
when I set async: false, it works for async calls

AjaxRequest.get (
{
'async': false,
'url': 'some url which requests a page that takes 10 secs to
load',
'timeout': 2000,
'onSuccess': 'some sucess which works',
'onTimeout': function(req) { alert('Timed out'); }
}
)

What am I doing wrong?

Thanks,
C

Matt Kruse wrote:
Chaprasi wrote:
Hi I need help with prototype while doing ajax calls. So this is my
JS which does a ajax calls


Prototype.js is generally avoided by most people in this group.
You won't find much help for it here.
this calls works fine but i need to know how I can set a timeout
saying after 5 seconds you should give up and show a message to the
user how can this be achieved.


I don't know if prototype supports timeouts, but my AjaxRequest library
does:
http://www.ajaxtoolbox.com/request/examples.php
does anyone
know if there is a official documentation for the library.


Part of the issue with prototype.js is that the documentation is almost
non-existent and there doesn't seem to be a good support system for the
library. So users end up coming here, for example, which is annoying.
Last is there a freebie library better than prototype.js


Yes. Many :)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


May 24 '06 #12

P: n/a
RobG <rg***@iinet.net.au> writes:
The issue stems from the fact that prototype.js modifies the prototype
of the in-built Array object. The same functionality could have been
achieved by creating a special prototype.js array object (say called
PTArray or _$A or whatever) and modifying that, but that's not how the
author chose to do it.


How would that work? Would "new PTArray" create and return a new
normal array and assign all the extra methods on each creation?

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
May 24 '06 #13

P: n/a
Lasse Reichstein Nielsen wrote:
RobG writes: <snip>
The same functionality could have been
achieved by creating a special prototype.js array object (say
called PTArray ...

<snip>
How would that work? Would "new PTArray" create and return
a new normal array and assign all the extra methods on each
creation?


It would pretty much have to as that is the only way of having an
object with the Array's special [[Put]] method. But why not as the
augmentation is only a set of assignments.

Richard.

May 24 '06 #14

P: n/a
try the following line right after you above code:

setTimeout( function(){
ajax1.transport.abort();
alert('Sorry, dude. I gave up on the call.');
} , 5000);

- Sergio Pereira

May 24 '06 #15

P: n/a
Guys any idea why this call is failing in Firefox, but in Internet
explorer it works fine.

AjaxRequest.get (
{
'async': false,
'url': 'some url which requests a page that takes 10 secs to
load',
'timeout': 2000,
'onSuccess': function(req) { alert('Sucess'); },
'onTimeout': function(req) { alert('Timed out'); }
}
)

So in IE this call is success but not in firefox. :(

Thanks,
C

se*******@gmail.com wrote:
try the following line right after you above code:

setTimeout( function(){
ajax1.transport.abort();
alert('Sorry, dude. I gave up on the call.');
} , 5000);

- Sergio Pereira


May 25 '06 #16

P: n/a
Chaprasi wrote:
Guys any idea why this call is failing in Firefox, but in Internet
explorer it works fine.
AjaxRequest.get (
{
'async': false,
'url': 'some url which requests a page that takes 10 secs to
load',
'timeout': 2000,


First of all, don't use async:false. It's generally a Bad Thing.

Second, a timeout won't work here because all code stops and waits for the
request to finish (thus, sync).

Simplify your problem: Use async.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
May 25 '06 #17

P: n/a
I agree with what you are saying. So how do I fire a validation check
where I need a response from the server like validating zip codes
without posting the form back. And what happens if this call times out
or if there is any network errors, how do I track those?

Can that be achieved with AjaxRequest?

Thanks,
C

Matt Kruse wrote:
Chaprasi wrote:
Guys any idea why this call is failing in Firefox, but in Internet
explorer it works fine.
AjaxRequest.get (
{
'async': false,
'url': 'some url which requests a page that takes 10 secs to
load',
'timeout': 2000,


First of all, don't use async:false. It's generally a Bad Thing.

Second, a timeout won't work here because all code stops and waits for the
request to finish (thus, sync).

Simplify your problem: Use async.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


May 26 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.