我可以在 SharePoint WebPart 中使用 jQuery ajax 而不必担心同源策略吗?
我当前的工作项目涉及开发一个将由我们的客户部署的 SharePoint 2007 WebPart。为了提供更好的用户体验,我通过将 IFRAME
的 SRC
属性设置为 HTTP 处理程序的地址来“模拟”ajax。这些处理程序部署到 12 个配置单元中的布局目录中。
虽然这可行,但我更喜欢使用 jQuery 的 $get()
方法。这在我的场景中是否可靠,或者我是否仍然受到同源政策的约束?将 WebPart 部署到 SharePoint 场的各个位置的场景怎么样?在这种情况下使用 $get()
会有什么问题吗?
同源策略是否会阻止我使用 $get
调用 HTTP 处理程序?
My current project for work involves developing a SharePoint 2007 WebPart which will be deployed by our clients. To provide a better user experience, I am "simulating" ajax via setting the SRC
attribute of an IFRAME
to be the address of an HTTP handler. These handlers are deployed to the layouts directory in the 12 hive.
Although this works, I would prefer to use the $get()
method of jQuery. Will this work reliably in my scenario or will I still be subject to the same origin policy? What about the scenario where the WebPart is being deployed to various places on a SharePoint farm? Will there be any problems with using $get()
in that case?
Would the Same Origin Policy prevent me from invoking an HTTP handler using $get
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过将
ashx
处理程序添加到12\TEMPLATE
文件夹,您可以将处理程序添加到应用程序上的所有网站和子网站。本质上,你有很多它们的副本。如果 AJAX 调用是相对于域的,例如
/_layouts/foo.ashx
,则不会受到同源策略的影响。与其他页面一样,处理程序安装在固定位置(例如管理中心)的其他方案将被策略阻止。
By adding the
ashx
handlers to the12\TEMPLATE
folder you are adding the handlers to all sites and sub-sites on your applications. Essentially, you have many copies of them.If the AJAX call is relative to the domain, for example to
/_layouts/foo.ashx
, it will not be affected by the same origin policy.Other scenarios, where the handlers are installed in a fixed location (e.g. Central Administration), will be blocked by the policy, same as every other page.
无论您是在本地还是远程运行,浏览器在正常查看模式下都会实现同源策略。域必须匹配。
The browser implements the same origin policy in normal viewing mode no matter if you are running locally or remotely. The domains must match.