网站之间的通信
我正在创建一个网站网络,这些网站应该在它们之间进行通信,例如让所有网站显示在其中一个网站上发布的文章,或者显示存储在另一个子域的数据库中的数据等等......
而这一切都使用ajax用于交互。
哪一种是实现这一目标的最佳(也是最简单)方法?
我认为 ajax 调用可以调用一个 php 脚本,该脚本可以调用另一个子域上的另一个脚本。这是正确的方法吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你到底想做什么。如果您控制站点和服务器,如果您跳过这种方式并在服务器本身上执行,则可以为所有用户节省大量 ajax 调用。
如果您使用 javascript 显示所有文章,没有 javascript 的用户将看不到任何内容,搜索引擎将无法抓取该网站。但是,也许这就是您想要的。
对于这样的事情,正确的设计模式是实现一个所有其他站点都可以读取的restful API。
所以你有一个中央API,例如。 http://api.example.com/
当服务器想要显示一篇文章时,他会做一些事情在后端检索文章列表..例如
http://api.example.com/retrieveNewestArticles
将返回例如。一个包含最新文章列表的 json 变量..然后当您想显示该文章时,您可以调用:
http://api.example.com/showArticle/58484
至少我会这样做。
有些人可能建议通过让所有网站直接连接到同一个数据库来实现这一点。这是一个选择,从长远来看有点混乱,但可以完成工作。
当然比我的建议更容易。
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.