Change the content of a DIV from another site

Asked

Viewed 129 times

1

Good afternoon,

I’m having a hard time finding a way to get two Ivs to communicate and I need help knowing what I can is using to make this communication

For example: An Object will send a site2 command and will change a url within a div on site1, because the goal is that I can open several links within that div without updating the page

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

  • You cannot perform commands between different domains. What you can do is upload all the html content of the site and work with it on your other site.

  • I understand, I had seen somewhere that there are tools that allow communication between them, so one just sends the command and the receiver when receiving this command, changes the contents of a div for example

1 answer

0

all right?

There is no "easy" way to do this, but you can create an endpoint on your server that does so using a controller and Angular/jQuery, for example.

Since you have not specified languages/server/database, etc., I will give a generic example.

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

You should 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 record it in the table "objects" - this will make the first controller (that populates your html) can see this data in the future.

So, just have the other application make a request in your new controller to be able to update the screen. The problem here is that it only changes if a page reloads.

If you still don’t need to refresh the page, you can use jQuery or angular to make an http request on your controller that populates the screen and "repopulate" the screen, without reloads.

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 on a different domain, you should add the "Access-Control-Allow-Origin" header in the request because of Cross Origin.

More about Cross Origin: insert link description here

I hope I’ve helped!

  • I think this can help me, I will study about the content you gave me, thank you, later I come back and comment better

Browser other questions tagged

You are not signed in. Login or sign up in order to post.