Bug Tracker

Opened 9 years ago

Closed 7 years ago

Last modified 6 years ago

#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:


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 9 years ago by robustsolution

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

comment:2 Changed 9 years ago by virajmody

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 9 years ago by dmethvin

Component: coreajax

comment:4 Changed 8 years ago by ishermandom

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 8 years ago by addyosmani

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 8 years ago by snover

Keywords: needsreview added

comment:8 Changed 8 years ago by snover

#4734 is a duplicate of this ticket.

comment:9 Changed 8 years ago by snover

Blocking: 5048 added

comment:10 Changed 8 years ago by snover

Keywords: needsreview removed
Milestone: 1.41.5
Priority: majorhigh
Status: newopen
Type: bugenhancement

comment:11 Changed 8 years ago by dmethvin

Keywords: needsdocs added

comment:12 Changed 7 years ago by Rick Waldron

Blocking: 5048 removed

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

comment:5 Changed 7 years ago by Rick Waldron

Keywords: ajaxrewrite added

comment:6 Changed 7 years ago by Rick Waldron

Keywords: getScript ajax needsdocs removed

comment:7 Changed 7 years ago by addyosmani

Keywords: needsdocs added
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) 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.

Version 0, edited 7 years ago by addyosmani (next)

comment:8 Changed 7 years ago by addyosmani

Keywords: neededdocs added; needsdocs removed
Note: See TracTickets for help on using tickets.