I was facing issue to post data
by a form to foreign domain. I am aware of "AJAX cross-domain policy". So we just can't call "http://yahoo.com" over ajax http request and display the results on my page. So after researching I found following:
i) To enable cross domain POST you have to enable 'Cross-Origin Resource Sharing' on both servers.
ii) Another easy way is to get cross-domain data using AJAX is to use a server side language as the proxy. Here's a small sample how to implement that using jQuery:
jQuery:
$.ajax({
url: 'proxy.php',
type: 'POST',
data: {
address: 'http://www.yahoo.com'
},
success: function(response) {
// response now contains full HTML of yahoo.com
}
});
PHP (proxy.php):
echo file_get_contents($_POST['address']);
Thanks for reading the blog
0 Comment(s)