Ajax, script, and 404: behavior changed after jquery upgrade

Ajax, script, and 404: behavior changed after jquery upgrade

Hello,

I am trying to upgrade my app from JQuery 2.2.4 to 3.2.1, and I get an error that I did not have before. I pared it down to the following simple example:
  1. <html>
  2. <head>
  3. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  4. <script>
  5.     $.ajax({
  6.         url: 'doesnotexist.js',
  7.         async: false,
  8.         dataType: 'script',
  9.         timeout: 500
  10.     });
  11. </script>
  12. </head>
  13. <body></body>
  14. </html>
In the Firefox console, I can see the 404-error on the GET request for the (non-existing) javascript file, followed by the error:
  1. SyntaxError: expected expression, got '<'  [Learn More]
What I think is happening, is that JQuery takes the error-document returned from the webserver, and tries to execute it as if it was a valid javascript file. The error-document of course contains html tags that start with '<'.
I would expect JQuery to not interpret an error-document (anything other than the response to a 200 result code) as a javascript file.

When I change the url-property to a javascript resource that does exist, the ajax call functions as expected; it executes that script that was fetched. Also, when I change the JQuery version to 2.2.4, the syntax error in the console disappears.

How can I prevent JQuery from trying to execute error-documents as javascript?

Thanks!