Bug Tracker

Modify

Ticket #1768 (closed bug: duplicate)

Opened 6 years ago

Last modified 4 years ago

$.getScript() never fails on load

Reported by: digitalspaghetti Owned by:
Priority: major Milestone: 1.4
Component: ajax Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

$pastemonkey('#recaptcha_div').livequery(function(){
		var self = this;
		$pastemonkey.getScript('http://notapi.recaptcha.net/js/recaptcha_ajax.js', function(){			
			setTimeout(function(){
				if (typeof Recaptcha != 'undefined') {
					Recaptcha.create("6LfncwAAAAAAAIxurXazJ0zspoEwBpeVUfNr87Hr", self);
				} else {
					$pastemonkey.unblockUI();
				};
			}, '5000');
		});
	});

Above is a workaround that I tried, that still always fails, the reason is the URL above is wrong, so the getScript should fail, however it never fails, so the unblockUI is never called, this freezes up my UI.

A suggestion to fix this is to pass in a timeout and a fail callback into the getScript function, something like:

.getScript('url',timeoutVal,successCallback,failCallback)

If the script is not recived within the timeoutVal, fire the failCallback otherwise successCallback

Attachments

1768.zip Download (1.5 KB) - added by davidserduke 6 years ago.
test cases for various situations
1768.diff Download (2.6 KB) - added by davidserduke 6 years ago.
patch (not complete)

Change History

comment:1 Changed 6 years ago by joern

  • Component changed from core to ajax

Changed 6 years ago by davidserduke

test cases for various situations

Changed 6 years ago by davidserduke

patch (not complete)

comment:2 Changed 6 years ago by davidserduke

Adding error handling to jsonp has some issues with the attached patch. These are the ones I've found so far:

Opera seems to load and execute the script synchronously so the timeout can't happen.

Firefox executes the code if it is loaded regardless of whether the timeout happens. So if a script takes 10 seconds to load and a timeout of 1 second is set. The timeout happens and reports failure to the functions. The script is removed from the document at that point, but 9 seconds later it will run. This is the only browser with this issue.

IE6/7 reports success on DNS failures and 404 document not found. I haven't found a way to figure out if it failed or not in those instances.

Safari reports success on 404 document not found (interestingly it reports failure on bad DNS unlike IE).

IMO this is an improvement over the existing code. I don't think it breaks anything that works currently, but rather fixes some of the previously failing cases. Unfortunately the bad cases aren't uniform across browsers so what works for some doesn't for others. I'm not sure which is better no error handling or inconsistent error handling.

Any ideas are welcome.

comment:3 Changed 6 years ago by davidserduke

See also #1863.

comment:4 Changed 5 years ago by flesler

The handler onerror works for Firefox, doesn't work on any other browsers. I thought one could put code inside a <script> with src and it'd gets executed if the url would fail (like <object>s). But no :(

comment:5 Changed 4 years ago by john

  • Status changed from new to closed
  • Version changed from 1.2.1 to 1.3.2
  • Resolution set to duplicate
  • Milestone changed from 1.2.2 to 1.4

We'll work on this in bug #3442.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.