Skip to main content

Bug Tracker

Side navigation

#5201 closed enhancement (wontfix)

Opened September 10, 2009 06:26PM UTC

Closed April 11, 2011 03:31AM UTC

Last modified March 10, 2012 08:21AM UTC

getScript should support an error callback, incorrect documentation

Reported by: virajmody Owned by:
Priority: high Milestone:
Component: ajax Version: 1.4.3
Keywords: ajaxrewrite, neededdocs Cc:
Blocked by: Blocking:
Description

Currently, $.getScript doesn't accept a function that can be invoked when an error occurs. The callback it does accept is only invoked on success, and both parameters passed to it are null/undefined.

Since the callback is success only, it doesn't need parameters I presume, so the documentation should be fixed. Also, an error callback provided to enable handling failure cases.

Attachments (0)
Change History (15)

Changed September 11, 2009 08:14AM UTC by robustsolution comment:1

Dear virajmody,

jQuery Allows you to return to the low level jQuery $.ajax(...) call if you need more callbacks and/or settings.

$.ajax is very simple to use.

all the high level abstraction AJAX calls like $.load(...),$.get(...), $.post(...), $.getScript(...), etc... are designed to fulfill some frequent AJAX tasks.

If you want to continue with using $.getScript(...) but with an additional callback for the error and you don't want to modify the jQuery library itself, you can use the global ajaxError callback event that has three parameter. the third one is the settings of the request that handled the error so you can test if(settings.dataType=='script' && settings.url=='...put it here') in the global ajaxError callback event to handle the getScript request that generates the error

Changed September 11, 2009 07:49PM UTC by virajmody comment:2

I tried using $.ajax with dataType = "script" but that too didn't seem to invoke an error callback.

I'll try the global ajaxError callback - thanks for that suggestion.

The documentation for $.getScript should be fixed regardless, though.

Changed December 10, 2009 04:20AM UTC by dmethvin comment:3

component: coreajax

Changed May 14, 2010 01:26AM UTC by ishermandom comment:4

I took a stab at adding error callbacks for remote scripts, which I assume would address this bug. See http://github.com/ishermandom/jquery/blob/15fc751ba6b39072c9ebf2548f2deaabe3257bc0/src/ajax.js.

Changed October 16, 2010 06:24PM UTC by addyosmani comment:5

I have added a reference to getScript as one of the areas of the API documentation which we need to update. Keeping this ticket open for now as there appears to have been a contribution made to address additional error callbacks that may want to be reviewed.

Changed October 18, 2010 10:26PM UTC by snover comment:6

keywords: getScript ajaxgetScript ajax needsreview

Changed October 21, 2010 01:24AM UTC by snover comment:7

#4734 is a duplicate of this ticket.

Changed October 21, 2010 01:24AM UTC by snover comment:8

blocking: → 5048

Changed October 21, 2010 01:25AM UTC by snover comment:9

keywords: getScript ajax needsreviewgetScript ajax
milestone: 1.41.5
priority: majorhigh
status: newopen
type: bugenhancement
version: 1.3.21.4.3

Changed November 21, 2010 01:19AM UTC by dmethvin comment:10

keywords: getScript ajaxgetScript ajax needsdocs

Changed December 27, 2010 08:39PM UTC by rwaldron comment:11

blocking: 5048

(In #5048) This needs to be reverified with the new ajax module.

Changed December 27, 2010 10:37PM UTC by rwaldron comment:12

keywords: getScript ajax needsdocsgetScript,ajax,needsdocs,ajaxrewrite

Changed January 01, 2011 11:00PM UTC by rwaldron comment:13

keywords: getScript,ajax,needsdocs,ajaxrewriteajaxrewrite

Changed April 11, 2011 03:31AM UTC by addyosmani comment:14

_comment0: I've just gone through the API docs for .getScript() and also put together a a live test case here: http://jsfiddle.net/64bDU/ using jQuery 1.5.2 demonstrating that the two parameters accepted by the success callback do in fact return values and *not* null/undefined as originally posted. In the case of the first parameter (data) you of course don't expect to get data returned, however the textStatus returns with a success message on completion. \ \ In my view, we may need to adjust the docs to clarify the limitations of .getScript(), however as the first reply correctly points out, if you need more than it provides, remember it's just a shorthand method and you can always fall back on $.ajax() for something requiring additional callbacks for errors etc. Closing as an error callback would probably creep into the territory of stopping this being just a short convenience path to achieving $.ajax()-related functionality.1310891673795085
keywords: ajaxrewriteajaxrewrite, needsdocs
resolution: → wontfix
status: openclosed

I've just gone through the API docs for .getScript() and also put together a a live test case here: http://jsfiddle.net/64bDU/ using jQuery 1.5.2 demonstrating that the two parameters accepted by the success callback do in fact return values and *not* null/undefined as originally posted. In the case of the first parameter (data) data is returned if available and the textStatus returns with a success message on completion. We've never claimed that error messages were available for this.

In my view, we may need to adjust the docs to clarify the limitations of .getScript(), however as the first reply correctly points out, if you need more than it provides, remember it's just a shorthand method and you can always fall back on $.ajax() for something requiring additional callbacks for errors etc.

Closing as an error callback would probably creep into the territory of stopping this being just a short convenience path to achieving $.ajax()-related functionality.

Changed July 17, 2011 09:51AM UTC by addyosmani comment:15

keywords: ajaxrewrite, needsdocsajaxrewrite, neededdocs