Ajax,检查更新,Same_origin_policy
我有这个 HTML 手册,它随我的应用程序一起安装。本手册经常更新(每周 3-5 次),如果本手册已过时,我想警告我的用户。
我想到的第一件事是创建一个到我的网络服务器的热链接图像,我可以用它来检查他们使用的版本并服务器“更新”图像或“无更新”图像。但如果用户没有互联网连接,图像将显示为损坏的图像。我不想要这样。
接下来,我考虑使用一些 Ajax 从我的网络服务器发出请求。如果用户没有互联网连接,Javascript 将能够正常失败。但我遇到了一个问题。由于该手册作为本地文件存储在用户 PC 上,因此被视为跨域请求(同源策略)从我的网络服务器发出请求。
还有什么建议可以尝试吗?
我不能只在开始菜单中包含指向手册在线版本的超链接,因为我的许多用户没有互联网连接。
I have this HTML manual that gets installed with my application. This manual gets updated often (3-5 times a week) and I want to warn my users if the manual is out of date.
The first thing I thought of was to create a hot-linked image to my webserver that I could use to check the version that they where using and server an 'update' image or 'no update' image. but if the user does not have an internet connection the image would show up as a broken image. And I don't want that.
Next I looked in to using a bit of Ajax to make the request from my webserver. If the user didn't have a interenet connection the Javascript would be able to fail gracefully. But I have run in to a problem. Because the manual is stored as a local file on the users PC it is considered a cross domain request (Same Origin Policy) to make request from my webserver.
Any suggestions on what else to try?
I can not just include a hyper link in the start menu to the online version of the manual, As many of my users will not have an internet connection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的第一直觉对我来说似乎是最简单的解决方案。
使用热链接图像来宣传更新。使用 ALT 文本隐藏损坏的图像并向用户显示有用的消息。
例如,您可以尝试:
为了更美观,在 CSS 中添加边框和一些填充,以便 IMG ALT 文本脱颖而出,而不仅仅是看起来像手册的常规文本部分。也许 1 像素的边框和 3 像素的边距/填充?
Your first intuition seems the simplest solution to me.
Use a hot-linked image to advertise an update. Use ALT text to hide the broken image and display a helpful message to the user.
For example, you could try:
To be fancy, in your CSS, add a border and some padding so the IMG ALT text stands out and doesn't just look like it's a regular text part of the manual. Maybe a 1px border and 3px of margin/padding?
使用带有回调函数的 $.post 来处理您的响应。这是“同源政策”安全的。
.post
use $.post with a callback function to handle your response. It's "same origin policy" safe.
.post
您可以使用 JSONP,在这里阅读更多内容:
http://www.jsonp.org west-wind.com/Weblog/posts/107136.aspx
http://niryariv.wordpress.com/2009/05/05/jsonp-quickly/
You could possibly use JSONP, read more of it here:
http://www.west-wind.com/Weblog/posts/107136.aspx
http://niryariv.wordpress.com/2009/05/05/jsonp-quickly/