From 9f83e8e33cf8a1da8fb57f8ef65e7207ec1fc6b5 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 4 Jul 2022 02:24:55 +0200 Subject: [PATCH] DEV: Use our `ajax` helper consistently (#17304) Possibly fixes some flakes, but regardless - we need to avoid using `$.ajax` directly in most cases. --- .../javascripts/discourse/app/lib/category-tag-search.js | 7 +++---- app/assets/javascripts/discourse/app/lib/user-search.js | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/category-tag-search.js b/app/assets/javascripts/discourse/app/lib/category-tag-search.js index 7313e872c81..3c39524c8cc 100644 --- a/app/assets/javascripts/discourse/app/lib/category-tag-search.js +++ b/app/assets/javascripts/discourse/app/lib/category-tag-search.js @@ -5,8 +5,8 @@ import { Promise } from "rsvp"; import { SEPARATOR } from "discourse/lib/category-hashtags"; import { TAG_HASHTAG_POSTFIX } from "discourse/lib/tag-hashtags"; import discourseDebounce from "discourse-common/lib/debounce"; -import getURL from "discourse-common/lib/get-url"; import { isTesting } from "discourse-common/config/environment"; +import { ajax } from "discourse/lib/ajax"; let cache = {}; let cacheTime; @@ -30,8 +30,7 @@ function searchTags(term, categories, limit) { discourseDebounce( this, function () { - oldSearch = $.ajax(getURL("/tags/filter/search"), { - type: "GET", + oldSearch = ajax("/tags/filter/search", { data: { limit, q }, }); @@ -50,7 +49,7 @@ function searchTags(term, categories, limit) { returnVal = cats.concat(tags); }) - .always(() => { + .finally(() => { oldSearch = null; resultFunc(returnVal); }); diff --git a/app/assets/javascripts/discourse/app/lib/user-search.js b/app/assets/javascripts/discourse/app/lib/user-search.js index 5fc019ab6df..35bc32892da 100644 --- a/app/assets/javascripts/discourse/app/lib/user-search.js +++ b/app/assets/javascripts/discourse/app/lib/user-search.js @@ -5,6 +5,7 @@ import discourseDebounce from "discourse-common/lib/debounce"; import { emailValid } from "discourse/lib/utilities"; import { isTesting } from "discourse-common/config/environment"; import { userPath } from "discourse/lib/url"; +import { ajax } from "discourse/lib/ajax"; let cache = {}, cacheKey, @@ -75,7 +76,7 @@ function performSearch( } // need to be able to cancel this - oldSearch = $.ajax(userPath("search/users"), { + oldSearch = ajax(userPath("search/users"), { data, }); @@ -102,7 +103,7 @@ function performSearch( returnVal = r; } }) - .always(function () { + .finally(function () { oldSearch = null; resultsFn(returnVal); });