# Are there any examples in Discourse of decorating a widget after an ajax request?

**URL:** <https://meta.discourse.org/t/are-there-any-examples-in-discourse-of-decorating-a-widget-after-an-ajax-request/44175>\
**Category:** Development\
**Created:** [12 Mayo, 2016 21:57 UTC](https://meta.discourse.org/t/are-there-any-examples-in-discourse-of-decorating-a-widget-after-an-ajax-request/44175 "2016-05-12T21:57:31Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![stevenpslade](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stevenpslade/32/53550_2.png) [@stevenpslade](https://meta.discourse.org/u/stevenpslade)\
**Post date:** [12 Mayo, 2016 21:57 UTC](https://meta.discourse.org/t/are-there-any-examples-in-discourse-of-decorating-a-widget-after-an-ajax-request/44175/1 "2016-05-12T21:57:31Z")

</div>

I would like to use `api.decorateWidget` after an `Discourse.ajax` has run.

```
api.decorateWidget('post-contents:before', dec => {
              const attrs = dec.attrs;
              const result = [];

              Discourse.ajax('/test', {
                type: 'GET',
                data: { topic_id: topic_id, group: group }
              }).then(function(res){
                if (res.test) {
                 //this push a virtual node into the result array
                  result.push(h('h1', 'test'));
                //this logs the virtual node and confirm virtual-dom works here
                  console.log(result);
              //expected result here is that api.decorateWidget gets the returned h1 virtual node and attached is, BUT it does nothing with no errors.
                  return result;
                }
             });

           });

```

#EDIT: AFTER RUNNING SOME TESTS  
So what all the code boils down to is…

1. The `decorateWidget` function
2. An `ajax` call inside the `decorateWidget`
3. An if statement in the result of the `ajax` call that returns a vDOM element

I put a `console.log` at each of these steps and got this (note: there are 2 posts on the thread I am testing on, which is why the widget decorator and ajax call runs twice):  
 ![](https://global.discourse-cdn.com/meta/original/3X/c/f/cf80039af9f5d6f837d41cf83f933a43617555d1.png)

Also, I am still not getting the vDOM element to return after the if statement.

---

_[View the full topic](https://meta.discourse.org/t/are-there-any-examples-in-discourse-of-decorating-a-widget-after-an-ajax-request/44175)._
