使用 jsonp 访问远程脚本时 cookie 是否有效?
我使用 jsonp 将表单发布到远程脚本。代码是这样的:
$.ajax({ type: "get", datatype: "jsonp", url: 'http://other-domain.com/process_form.php?param1=x&' + $("#gs_vote_form").serialize(), data: $("#gs_vote_form").serialize(), success: function(data) { alert('form submitted successfully'); } });
表单已提交,但是... process_form.php 完全忽略属于“其他域”的 cookie 数据(不读取或写入它们),这对我来说是问题。
请注意,我不关心返回的数据,我只使用 jsonp 将表单从一个站点静默提交到另一个站点,而不实际将用户转移到另一个站点。
有什么解决方法吗?有什么东西可以让 cookie 发挥作用吗?
i use jsonp to post a form to a remote script. the code is something like this:
$.ajax({ type: "get", datatype: "jsonp", url: 'http://other-domain.com/process_form.php?param1=x&' + $("#gs_vote_form").serialize(), data: $("#gs_vote_form").serialize(), success: function(data) { alert('form submitted successfully'); } });
The form IS submitted, but... The process_form.php completely ignores cookie data that belong to the "other-domain" (does not read or write them), which is the problem for me.
Please note, i do not care about the returned data, i only use jsonp to submit the form from one site to the other silently, without actually transferring the user to the other site.
Is there any workaround for this? Something that will make cookies work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
什么浏览器?
其他域
上的 Cookie 将是“第三方 Cookie”,因此在 IE 中受到更严格的控制,如“隐私”设置选项卡中配置的那样。这意味着,对于 IE 的默认设置,other-domain
将被阻止使用 cookie,除非它设置了 P3P 政策。 (其他浏览器不使用 P3P,因为许多人认为这是毫无意义的骗子宪章。)真的,您确定
other-domain
允许使用;
作为替代参数吗&
的分隔符?遗憾的是 PHP 不支持这一点,除非显式重新配置这样做。What browser?
Cookies on
other-domain
will be ‘third-party cookies’, and thus in IE subject to tighter controls, as configured in the ‘privacy’ settings tab. That means, for IE's default settings, thatother-domain
will be prevented from using cookies unless it sets a P3P policy. (Other browsers don't use P3P as many consider it a somewhat pointless Liar's Charter.)Really, are you sure
other-domain
allows the use of;
as an alternative parameter separator to&
? Sadly PHP does not support this unless explicitly reconfigured to do so.