views:

115

answers:

1

I am dynamically adding script tags to the DOM so I can download JSON data. Occasionally something goes wrong with a download, and the script fails to load properly.

How do I tell the browser to give up on a script that has taken too long to load? I think this is important because the browser limits the number of open requests at one time, and I don't want to waste it with dead connections.

I tried removing the script tag from the DOM, but that seems to have no effect.

+1  A: 

I'm not sure that you can control how the browser loads a script once you've inserted it into the DOM.

However, if you use an XMLHttpRequest to download the JSON data, you can call the abort method if the request takes too long.

Steve

Steve Harrison
I was hoping to avoid XMLHttpRequests if possible. The cross-domain security is a whole different problem.
matt
If your server supports PHP, you can write a PHP script that gets the contents of a remote webpage (PHP isn't limited by cross-domain security), and then just make an XMLHttpRequest to your PHP script. It sounds complicated, but it works.
Steve Harrison