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 comment:1
Changed September 11, 2009 07:49PM UTC by 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 comment:3
component: | core → ajax |
---|
Changed May 14, 2010 01:26AM UTC by 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 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 comment:6
keywords: | getScript ajax → getScript ajax needsreview |
---|
Changed October 21, 2010 01:24AM UTC by comment:8
blocking: | → 5048 |
---|
Changed October 21, 2010 01:25AM UTC by comment:9
keywords: | getScript ajax needsreview → getScript ajax |
---|---|
milestone: | 1.4 → 1.5 |
priority: | major → high |
status: | new → open |
type: | bug → enhancement |
version: | 1.3.2 → 1.4.3 |
Changed November 21, 2010 01:19AM UTC by comment:10
keywords: | getScript ajax → getScript ajax needsdocs |
---|
Changed December 27, 2010 08:39PM UTC by comment:11
blocking: | 5048 |
---|
(In #5048) This needs to be reverified with the new ajax module.
Changed December 27, 2010 10:37PM UTC by comment:12
keywords: | getScript ajax needsdocs → getScript,ajax,needsdocs,ajaxrewrite |
---|
Changed January 01, 2011 11:00PM UTC by comment:13
keywords: | getScript,ajax,needsdocs,ajaxrewrite → ajaxrewrite |
---|
Changed April 11, 2011 03:31AM UTC by 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: | ajaxrewrite → ajaxrewrite, needsdocs |
resolution: | → wontfix |
status: | open → closed |
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 comment:15
keywords: | ajaxrewrite, needsdocs → ajaxrewrite, neededdocs |
---|
Docs updated: http://api.jquery.com/jQuery.getScript/
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