网站之间的交流 [英] Communication between websites

查看:78
本文介绍了网站之间的交流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个网站网络,这些网站之间应该进行交流,例如,让所有这些网站都显示其中一个发布的文章,或者显示存储在另一个子域的数据库中的数据,等等...



而所有这些都使用ajax进行交互。



以下哪一种是实现这一目标的最佳(最简单)方式?



我认为ajax调用可以召唤一个php脚本,该脚本可以调用另一个子域上的另一个脚本。



谢谢

解决方案

我不这样做吗?完全不知道您想做什么。如果您控制站点和服务器,则可以跳过所有操作并在服务器本身上进行操作,从而为所有用户节省大量的ajax调用。



如果通过使用javascript显示所有文章,没有javascript的用户将看不到任何内容,并且搜索引擎将无法抓取网站。.但是,也许这就是您想要的。



诸如此类的正确设计模式是实现一个宁静的API,所有其他站点都可以从中读取。.



因此,例如,您有一个中央API。 http://api.example.com/



并且当服务器要显示文章时,他会在后端执行某些操作以检索文章列表。



http://api.example.com/retrieveNewestArticles



会返回例如一个带有最新文章列表的json变量。然后,当您要显示该文章时,您将调用:



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



我就是这样



有人可能建议通过使所有网站直接连接到同一数据库来做到这一点。这是一个选择,从长远来看比较麻烦,但是可以完成工作。



肯定比我的建议容易。


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

解决方案

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.

这篇关于网站之间的交流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆