# כיצד לרענן ווידג'ט מסוים לאחר קבלת נתונים מ-ajax

**URL:** <https://meta.discourse.org/t/how-to-refresh-a-particular-widget-after-getting-data-from-ajax/189616>\
**Category:** Development\
**Created:** [7 במאי,‏ 2021,‏ 10:57am UTC](https://meta.discourse.org/t/how-to-refresh-a-particular-widget-after-getting-data-from-ajax/189616 "2021-05-07T10:57:47Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)\
**Post date:** [7 במאי,‏ 2021,‏ 9:08pm UTC](https://meta.discourse.org/t/how-to-refresh-a-particular-widget-after-getting-data-from-ajax/189616/2 "2021-05-07T21:08:45Z")

</div>

The issue here is that your code to add the new nav items only fires once the ajax request is resolved. So, in the very few milliseconds it takes to do that, the default (unmodified) nav is displayed. That’s why you see it on the initial page view.

Once you navigate to another page, the request will have resolved, and your changes would then start working.

To answer your question, yes, you can conditionally rerender a component.

That said, it’s not really the answer you’re looking for. You don’t even need the ajax request. You can get the list of categories from the application directly. This fixes your problem and saves you an extra HTTP request. Try something like this (based on your code).

```javascript
// lookup categories
const categoryList = api.container.lookup("site:main").categories;

// add a nav item for each category
categoryList.map(val => {
  api.addNavigationBarItem({
    name: val.name,
    displayName: val.name,
    title: val.name,
    href: `/c/${val.slug}`,
    forceActive: (category, args, router) => {
      return router.currentURL === `/c/${val.slug}`;
    }
  });
});

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-refresh-a-particular-widget-after-getting-data-from-ajax/189616)._
