1

I'm really stumped on this one. I'm trying to upgrade our jQuery version (using jQuery-migrate-3.0.0.js) and getting the error "JQMIGRATE: jQuery.unique is deprecated, use jQuery.uniqueSort" on the following code (seems to be on the return $('body').attr('data-token'):

(function ($) {
    aSite.getAntiForgeryToken = function () {
        return $('body').attr('data-token');
    };

    var antiForgeryToken = aSite.getAntiForgeryToken();

    $(document).on('ajaxSend', function (e, xhr, options) {
        try {
            if (!options.crossDomain && antiForgeryToken) {
                xhr.setRequestHeader('X-CSRF-Token', antiForgeryToken);
            }
        }
        catch (ex) {
            console.log('an error occurred attaching the token to the request', ex);
        }
    });
})(jQuery);

I don't see how this involves jQuery.Unique() at all. I've tried a ton of fixes for this (all from this site!) but I can't seem to get past this function.

Thanks for any help you can provide

Addition: the error message in more detail:

11:18:11.945 JQMIGRATE: jQuery.unique is deprecated, use jQuery.uniqueSort jquery-migrate-3.0.0.js:62:12
11:18:11.947 console.trace() jquery-migrate-3.0.0.js:64:13
    jQuery 6
        migrateWarn
        get
        find
        init
        init
        jQuery
    getAntiForgeryToken https://localhost/ASBUILD/js/shared/aSite.js:1932
    <anonymous> https://localhost/ASBUILD/js/shared/aSite.js:1935
    <anonymous> https://localhost/ASBUILD/js/shared/aSite.js:1947
  • Are you upgrading from 1.12.x or 2.2.x? – BenTheHumanMan Jul 22 '21 at 20:27
  • also, can you share how you are importing the jquery scripts? – BenTheHumanMan Jul 22 '21 at 20:28
  • 1
    Are you sure this code is triggering the warning? If you're not using `jQuery.unique()` explicitly in your code, it could be coming from a library you load. – Barmar Jul 22 '21 at 20:29
  • I began the upgrade from 1.7.2 but have resolved enough issues to be running with 1.9.0 and jquery-migrate-3.0.0. – arcturusrann Jul 23 '21 at 12:14
  • A .cs file in the solution is used to preload all the jquery files: `bundles.Add(new RawScriptBundle("~/bundles/jquery").Include( "~/js/lib/jquery-{version}.js", "~/js/lib/jquery-migrate-{version}.js"));` – arcturusrann Jul 23 '21 at 12:18
  • The only reason I think this code is triggering the warning is that when I'm running the log in page in a console debugger, it singles out this code. I've searched all project files for jQuery.unique() and it is not used at all in the solution. – arcturusrann Jul 23 '21 at 12:20
  • When you have the warning, click on the little dropdown arrow and copy paste the whole path that goes and checks every file and edit your post to include it. Thanks. – Costa Jul 23 '21 at 13:31
  • Thanks Costa, I've updated the post with the messages including paths. – arcturusrann Jul 23 '21 at 15:24
  • On your [other question](https://stackoverflow.com/questions/69270729/jquery-unique-is-not-a-function) (and hidden in the comments above) you *comment* that you're using jquery-1.9.0 with migrate-3.0.0 - you need to migrate to 1.12.x *first*. – freedomn-m Sep 21 '21 at 15:02
  • Does this answer your question? [Migrating jQuery from 1.4 to 3.0](https://stackoverflow.com/questions/45789166/migrating-jquery-from-1-4-to-3-0) – freedomn-m Sep 21 '21 at 15:02

0 Answers0