Render server response to ember main view

AI-generated summary

Render server response to ember main view

The discussion revolves around rendering server responses to the Ember Main View. EndruK is currently appending content retrieved from the server to a div using jQuery, but the content remains displayed even after navigating to another page.

EndruK shares their Ember Controller code, which uses Discourse.ajax to retrieve content from the server and append it to the div. The goal is to render the response in the place where the content for a route is displayed.

eviltrout seeks clarification on where the content should appear and when it should disappear. EndruK explains that they want the response to be rendered in the place where the content for a route is displayed.

eviltrout suggests looking at the discourse-adplugin as an example of creating a component that is displayed on every “page” of Discourse. EndruK finds this helpful, realizing they can use outlets to achieve their goal.

Hi,
I retrieve some content from my server and want to render it to the Ember Main View.

Currently I add a div called disraptorView and append via jQuery the Content retrieved from the server controller.
The Problem is: once there is some content in this div it is always displayed when someone is navigating on the page.

I want to render my response to the Ember Main View but I have no idea how to properly do that.

This is my Ember Controller:

export default Ember.Controller.extend({
  init: function() {
    this.send('loadContent');
  },
  actions: {
    loadContent() {
      var pathArray = window.location.pathname.split('/');
      var subpath = pathArray[pathArray.length-1];
      var type;
      type = (subpath == "") ? "main" : "sub";
      Discourse.ajax({
        url: `/disraptor`,
        type: 'GET',
        dataType: 'text',
        data: {"url":subpath,"type":type}
      })
      .then(function(result) {
        $(".disraptorView").empty();
        $(".disraptorView").append($(result));
      })
      .catch(function(error) {
        console.log(error);
      });
    }

  }
});

Here is what it produces:

and when I move to another page on the client:

I’m not clear what you mean by this - where do you want your content to appear and when do you want it to go away? If you could show an example we can probably help you better.

I want that my response is rendered in the place where the content for a route is displayed.

I suggest you look at the discourse-adplugin for an example of how to create a component that is displayed on every “page” of discourse.

Ah thanks, that helped a lot.
I forgot that there are outlets to do that stuff …