#5201 closed enhancement (wontfix)
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.
Change History (15)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
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.
comment:3 Changed 13 years ago by
Component: | core → ajax |
---|
comment:4 Changed 13 years ago by
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.
comment:5 Changed 12 years ago by
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.
comment:6 Changed 12 years ago by
Keywords: | needsreview added |
---|
comment:9 Changed 12 years ago by
Blocking: | 5048 added |
---|
comment:10 Changed 12 years ago by
Keywords: | needsreview removed |
---|---|
Milestone: | 1.4 → 1.5 |
Priority: | major → high |
Status: | new → open |
Type: | bug → enhancement |
Version: | 1.3.2 → 1.4.3 |
comment:11 Changed 12 years ago by
Keywords: | needsdocs added |
---|
comment:12 Changed 12 years ago by
Blocking: | 5048 removed |
---|
(In #5048) This needs to be reverified with the new ajax module.
comment:5 Changed 12 years ago by
Keywords: | ajaxrewrite added |
---|
comment:6 Changed 12 years ago by
Keywords: | getScript ajax needsdocs removed |
---|
comment:7 Changed 12 years ago by
Keywords: | needsdocs added |
---|---|
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.
comment:8 Changed 12 years ago by
Keywords: | neededdocs added; needsdocs removed |
---|
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