Change the contents of a DIV from another site

1

Good afternoon,

I'm having a hard time finding a way to make two divs communicate and I need help finding out what I can use to make this communication

For example, an object will send a command from site2 and will change a url inside a div on site1, because the goal is that I can open multiple links within that div without refreshing the page

I should have searched wrong, but I have not found a tool that can make this connection where site2 sends the command and site1 executes

    
asked by anonymous 24.05.2016 / 22:43

1 answer

0

Alright?

There's no easy way to do this, but you can create an endpoint on your server that does this by using a controller and Angle / jQuery, for example.

As you did not specify languages / server / database, etc., I'll give you a generic example.

Let's suppose that the controller that populates your html initially simply takes the data from the table "objects" of the database and returns to the screen.

You must create another controller in your project, which receives data (usually in json). Then the other project should send a request to this controller with the data you want to add. Take this data, and write it in the table "objects" - this will make the first controller (which populate your html) can see this data in the future.

So, it is enough that the other application makes a request in its new controller so that it is able to update the screen. The problem here is that it only changes if a reload occurs on the page.

If you still do not want the page to be updated, you can use jQuery or angular to make an HTTP request on your controller that populates the screen and "repopulates" the screen, without reloading.

An example with jquery would be:

$.get('/populaDados', function (response) {
    $(body).html(response); //aqui você deve tratar a resposta para repopular a tela.
});

This is just an example, you can create the controller and use the object in jQuery as you like.

ATTENTION If the project that sends the data is in a different domain, you must add the "Access-Control-Allow-Origin" header in the request because of Cross Origin.

More about Cross Origin: insert the link description here

I hope I have helped!

    
25.05.2016 / 04:28