New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$.getScript().abort() does not abort its request (as well as $.ajax({ dataType: "script" })) #4912
Comments
One more clarification.
|
OK, one more. If we set |
Thanks for the report. The script transport uses a script tag to inject JS code and, unfortunately, there's no way to abort a request triggered by adding a script tag. |
Dear @mgol, thanks for the answer. So if it can’t be aborted, it should not trigger fail callbacks, right? But it does trigger. So this inconsistency looks like a problem for me. |
Hmm, that looks inconsistent, indeed. I'll reopen so that the team can discuss this. Thanks! |
Discussed in the meeting. We're not sure the right solution here. While it is inconsistent that the failure callback gets called, the script execution can't really be aborted. There's an argument that it's best to leave this as-is but add a clearer error message to promise rejection in the script transport abort method, simply stating that it can't be aborted. |
Hi @timmywil, thanks for this update. It would be awesome if you clarify what is an argument to call fail callback even when there is no fail event. |
The fail event event is that it fails to abort. To silently fail seems worse and would lead to unexpected behavior. It would be best not to call abort at all, but we can fix that with the right error message. |
That said, we can add some clarification to the docs about this. While all ajax requests have abort methods, not all of them are useful. |
I’m not sure if I understand it well. |
I see what you mean. This is true most of the time, but in the end it's just a Promise/Deferred. It can be rejected for other errors as well, including logic errors, errors in done/then callbacks, and, in this case, an error attempting to change the request. Another idea was to throw an error in the abort method (instead of rejecting the promise), but I think that has more potential to break existing code. It would just halt the stack. My argument was that fail callbacks are already getting called; they might as well get called with a more helpful error message. I don't know if there's a perfect solution. But imagine not calling any callbacks after calling abort and later the script still gets executed. That seems like the worst of the 3 options so far. |
Description
Both
$.ajax()
and$.getScript()
requests are aborted after requesting.abort()
method on them.$.ajax()
aborts well,$.getScript()
does not abort its network request. Both of them triggers.fail(failCallback)
callback as expected.I am testing on latest Chrome 92.0.4515.107 on Mac OS 10.14.6.
Link to test case
https://jsbin.com/kasonuqobu/1/edit?html,js,output
The text was updated successfully, but these errors were encountered: