通过 Ajax 将数据发送到外部文件
当我使用此代码时,它可以工作:
ajax.open("post","a.php",true);
但是当我尝试将数据发送到外部文件时,例如:
ajax.open("post","http://www.example.com/a.php",true);
它不起作用。
有什么解决办法吗?
When I use this code, it works:
ajax.open("post","a.php",true);
but when I try to send data to a external file like:
ajax.open("post","http://www.example.com/a.php",true);
it doesn't work.
Are there any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
必须打开的文件的 URL - 服务器端脚本的位置。这可以是绝对 URL,如 (http://www.foo.com/bar.php) 或相对 URL (/bar.php)。请注意 - 此 URL 应与脚本位于同一域中。您无法从 yahoo.com 中运行的脚本调用 google.com 中的脚本。这是大多数浏览器中实施的防止 XSS 的安全措施。
问候,
西里尔
The URL of the file that must be opened - the location of the server side script. This can be a absolute URL like(http://www.foo.com/bar.php) or a relative one(/bar.php). A note of caution - this URL should be in the same domain as the script is. You cannot call a script in google.com from a script that is running in yahoo.com. This is a security measure implemented in most browsers to prevent XSS.
Regards,
Cyril
您的脚本在哪个域上执行?是 www.site.com 还是其他?
您的代码可能无法工作的原因是出于安全原因您不允许向其他域发送 AJAX 请求。
编辑:一种解决方法是在 mysite.com 上实现 Web 服务,向其发送 AJAX 请求。然后,该服务应将原始请求代理到 othersite.com(服务器端),并随后将响应返回到在 mysite.com 上执行的脚本。
On which domain is your script executed? Is it www.site.com or some other?
The reason your code might not work is because for security reasons you are not allowed to send AJAX request to other domains.
Edit: One workaround would be to implement a web service on mysite.com, send AJAX request to it. The service should then proxy the original request to othersite.com (server-side) and subsequently return the response to the script being executed on mysite.com.