How can I load cross domain HTML page with jQuery AJAX?
Suppose I want to get a page outside my domain using jQuery AJAX:
$.get('http://www.domain.com/mypage.html', function(data) {
alert(data);
});
I will probably get this error message:
XMLHttpRequest cannot load http://www.domain.com/path/filename. Origin null is not allowed by Access-Control-Allow-Origin.
we can't load cross domain page using AJAX because of the Same-origin policy.
I could try using 'jsonp' to bypass this restriction:
$.ajax({
type: "GET",
url: url,
dataType: "jsonp",
success: function(data){
console.log(data);
}
});
But what if 'jsonp' is not supported in this site? this could be a problem.
What if I just want to read an external page and parse its HTML?