jQuery 表单插件 - 将文件上传到不同的域

发布于 2024-11-17 13:43:02 字数 806 浏览 6 评论 0原文

我有一个 asp.net 网站,该网站应该将文件从不同的应用程序/域上传到处理程序。我正在使用 jQuery 表单插件。当尝试在同一域上制作示例(上传到同一域)时,此设置可以成功。当尝试从 siteA 上传文件到 siteB 时,我在 firebug 中看到处理程序的响应已返回(在“网络”选项卡中)并且有效,但是,代码从未进入“成功”处理程序,而是在firebug控制台:

[jquery.form] Server abort: Error: Permission denied to access property 'document' (Error) log: 
[jquery.form] cannot access response document: Error: Permission denied to access property 'document'
[jquery.form] aborting upload... aborted

在chrome中是:

Unsafe JavaScript attempt to access frame with URL http://domainB/handler.ashx from frame with URL domainA. Domains, protocols and ports must match.

现在,我知道有一些关于域之间ajax调用的策略,但似乎jquery表单插件只是尝试访问一些被禁止的url。 有人有解决方法吗?请任何解决方案!:)

更新: 我最终破解了 jquery.form,这样它就不会抛出跨站点异常,并且因为我不需要上传的实际结果 - 它对我有用!

I have a asp.net website which is supposed to upload files to a handler from a different application / domain. I'm using jQuery Form plugin. When trying to make an example on the same domain (uploading to the same domain) this setup works with success. When trying to upload file with from siteA to siteB I see in firebug that response from handler has been returned (in the Network tab) and is valid, however, the code never enters the 'success' handler, instead giving me such errors in the firebug console:

[jquery.form] Server abort: Error: Permission denied to access property 'document' (Error) log: 
[jquery.form] cannot access response document: Error: Permission denied to access property 'document'
[jquery.form] aborting upload... aborted

In chrome it is:

Unsafe JavaScript attempt to access frame with URL http://domainB/handler.ashx from frame with URL domainA. Domains, protocols and ports must match.

Now, I am aware of the fact that there are some policies about ajax calls between domains, but it seems that jquery form plugin simply tries to access some url that is forbidden.
Does anyone have a workaround for it? Any solution please!:)

UPDATE:
I ended up hacking jquery.form so it doesn't throw cross-site exception and since I don't need actual result of upload - it works for me!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2024-11-24 13:43:02

检查一下,是的,这是同源策略。有多种方法可以使用 flash、iframe、jsonp 等来解决此问题,但这需要编辑插件。

Check this and yes, this is a same-origin policy. There are ways to work this around using flash, iframes, jsonp etc but this will require editing a plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文