Communication between websites

∥☆過路亽.° 提交于 2019-12-11 23:51:28

问题


I'm creating a network of websites that should communicate between themselves, for example to let all of them display an article published on one of them, or display data stored in a database of another subdomain, etc...

And this all using ajax for interactivity.

Which could be the best (and simplest) way to achieve this?

I thought an ajax call could summon a php script that could call another script on another subdomain. Is it the right way?

Thanks


回答1:


I don't know exactly what you want to do. If you control the sites and server you could save all your users a lot of ajax calls if you skip doing it that way and do it on the server itself.

If you display all the articles by using javascript, users without javascript won't see anything and search engines won't be able to crawl the website.. however, maybe that's what you want.

The correct design pattern for something like this is to implement a restful API that all the other sites read from..

So you have a central API on eg. http://api.example.com/

and when a server wants to display an article, he would do something on the back end to retrieve an article list.. eg.

http://api.example.com/retrieveNewestArticles

that would return eg. a json variable with a list of the newest article.. then when you want to display that article, you would call:

http://api.example.com/showArticle/58484

That's how I would do it at least.

Some people might suggest doing it by making all the websites connect directly to the same database. That's an option, a bit more messy in the long run, but will get the job done.

certainly easier than my suggestion.



来源:https://stackoverflow.com/questions/5068217/communication-between-websites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!