Ajax Timeouts

C

Chaprasi

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
 
M

Matt Kruse

Chaprasi said:
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 :)
 
C

Chaprasi

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
 
R

Randy Webb

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.


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/>
 
R

RobG

Tony said:
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 Library Info.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...
 
P

petermichaux

I'm not particularly pro prototype.js but
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
 
R

RobG

I'm not particularly pro prototype.js but


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
 
R

Richard Cornford

RobG wrote:
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.
 
C

Chaprasi

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
 
L

Lasse Reichstein Nielsen

RobG said:
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
 
R

Richard Cornford

Lasse said:
RobG writes:
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.
 
S

sergioafp

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
 
C

Chaprasi

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
 
M

Matt Kruse

Chaprasi said:
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.
 
C

Chaprasi

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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top