Sending data to an external file via Ajax

試著忘記壹切 提交于 2019-12-25 06:46:04

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5597596/sending-data-to-an-external-file-via-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!