All jobs

Fix $.ajax(...).success Is Not a Function After a jQuery Upgrade

Yes. An agent reproduces the TypeError on jQuery 3, moves every success, error and complete callback to done, fail and always, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads how jQuery gets onto the page. In a browser app like therewasaguy/p5js-webIDE, package.json pins jquery at ~2.1.4 beside gulp 3.9 and gulp-browserify, app/main.js line 6 does var $ = require('jquery'), and gulpfile.js lines 22 to 43 bundle app/main.js with Browserify, uglify it, and concatenate app/libs/jquery.min.js and jquery-ui.min.js in front of it into public/js/main.js. So the page carries two copies: the 2.1.4 file checked into app/libs/, and whatever version Browserify pulls from node_modules, which is the one the application code calls.

It then finds every call that depends on the old names. app/main.js lines 332 to 336 call $.ajax({url: '/authenticate', type: 'get'}).success(function(res) {...}) and line 358 already uses .fail; app/ajax.js has five $.ajax calls at lines 24, 78, 120, 150 and 187, with .success( at lines 30, 83 and 125 and .error( at lines 59, 106 and 129. A grep for .size(), .live(, andSelf and $.parseJSON finds only a commented-out line, so the jqXHR callbacks are the whole of this upgrade's breakage.

Then it reproduces both states under jsdom, since the repository's own gulp 3 build does not start on a current Node and its node-sass 3 dependency needs npm install --ignore-scripts to get past. With jquery@2.1.4 bound to a jsdom window, a jqXHR from $.ajax has success, error and complete beside done, fail and always. After npm install jquery@3, which resolves 3.7.1, the first three are undefined and the same chain throws TypeError: jqxhr.success is not a function; the current major, jQuery 4.0.0, reached under Node through its jquery/factory export, is the same. The methods were deprecated in 1.8 and removed in 3.0.

The fix is a rename at each site: .success( becomes .done(, .error( becomes .fail( and .complete( becomes .always(, with the same callbacks and the same (data, textStatus, jqXHR) and (jqXHR, textStatus, errorThrown) arguments, so no handler body changes. The agent also replaces the 2.1.4 file in app/libs/ with the same release it put in package.json, so the page does not ship two majors of jQuery, and reads the version line at the top of jquery-ui.min.js, which says jQuery UI - v1.11.4 - 2015-12-25: a build from before jQuery 3, so the pull request names the jQuery UI upgrade to 1.12 as a separate step rather than bundling widget changes into this one.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "This browser app fails with \"TypeError: $.ajax(...).success is not a function\" after upgrading jquery. Read package.json, the build script and every file that calls $.ajax first, and say how jQuery reaches the page, including any copy checked into the repository. Reproduce the error under jsdom with the locked jquery and with the current major, quoting the methods present on the jqXHR in each. Replace each success, error and complete callback with done, fail and always at every call site, keep the handler bodies as they are, update any checked-in jQuery copy to the same release, and check that jQuery UI or other plugins on the page support that release. If the repository's own build cannot run on a current Node, say so and what you used instead. Open a pull request that quotes the failing and passing checks.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request touching app/main.js, app/ajax.js, package.json and app/libs/jquery.min.js: seven callback names changed across the two source files, the jquery range moved to the current major, and the checked-in copy replaced with the same release. The description quotes the jsdom check on 2.1.4 and 3.7.1 with the TypeError, lists each line it changed, names the jQuery UI - v1.11.4 build it found as the next upgrade, and says the gulp 3 pipeline could not be run on the sandbox's Node, so the bundle was not rebuilt there.

A reviewer checks that every $.ajax call site is covered, that the handlers' bodies and argument order are unchanged, that app/libs/ and package.json name the same jQuery, and that the jQuery UI build on the page supports it. The run's record has both jsdom runs with their full output, so the before and after can be read rather than taken on trust.

Run it on every Monday morning

Add an automation to the Project with this prompt and a schedule trigger, cron set to 0 9 * * 1 in your timezone. Each Monday one run bumps jquery, checks the jqXHR methods under jsdom and opens one pull request on its own branch when a call site breaks; a week already on the current major opens nothing, and a week where a plugin on the page has no build for the new jQuery ends needs_review with the plugin named.

The same body works from your own code with POST /o/{org}/sessions and an API key when a dependency bot's jquery bump turns the page blank; send a request_id that is a UUID v5 of the bot's pull request number so a retried start returns the same run, and the key's webhook_url receives run.completed or run.failed with the session URL when it ends.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

This break never shows in a build. Browserify bundles the new jQuery without complaint, and the TypeError fires in the browser the first time a user signs in or saves. The agent reproduces it under jsdom in its sandbox, at the locked version and the new one, and every command and its output stays in the run's record, so the pull request shows the exact methods that vanished rather than a guess from the changelog.

An old front end also carries history the diff does not show: a second jQuery checked into a folder, a jQuery UI build from the same era, a gulp pipeline that no longer starts. The agent reads all of it, says in the pull request what it could and could not run, and leaves the reviewer with a list of call sites and versions instead of a promise.

Frequently asked questions

Why were success, error and complete removed?

They were jqXHR-only aliases for the Deferred methods done, fail and always, deprecated in jQuery 1.8 and removed in 3.0 so one promise API remains. The replacements take the same arguments in the same order, which is why the pull request changes only the method names.

Does the checked-in jquery.min.js matter if the app requires jquery from npm?

In this repository both end up in public/js/main.js: the file from app/libs/ is concatenated in front of the Browserify bundle that contains the npm copy. The application code uses the npm copy, which is why the upgrade breaks it, and the agent replaces the file so the page does not ship two majors.

Can the agent run the gulp build?

Not on a current Node: gulp 3 stops on start and node-sass 3 fails to compile during npm install. The agent installs with --ignore-scripts, proves the change under jsdom, and says in the pull request that the bundle was not rebuilt. Give it a Node version in the prompt if the project's CI still uses one that gulp 3 runs on.

What about jQuery UI?

jQuery UI 1.11 and earlier were written against jQuery 1 and 2; 1.12 is the first line that supports jQuery 3. The checked-in jquery-ui.min.js in this repository is 1.11.4, so the agent names that upgrade in the pull request as a separate step, since widget code can change between UI releases and deserves its own review.

More jobs like this: Upgrade dependencies weekly

Keep reading