How can I load an html cross-domain page using jQuery AJAX?

How can I load a cross-domain HTML page using 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 . The origin of null is not allowed by Access-Control-Allow-Origin.

we cannot load a cross-domain page using AJAX due to policies of the same origin .

I could try using "jsonp" to get around this limitation:

$.ajax({
  type:     "GET",
  url:      url,
  dataType: "jsonp",
  success: function(data){
    console.log(data);
  }
});

But what if "jsonp" is not supported on this site? this can be a problem.

, HTML?

+4
2

, . , , - , .

. - , CORS www.domain.com

, , :

, HTML URL-. ( )

JS:

var encodedUrl = encodeURIComponent('http://www.domain.com/mypage.html');
$.get('http://www.yourdomain.com/getcontent?url=' + encodedUrl, function(data) {
    console.log(data);
});

URL- .NET - /getcontent

0

AJAX Cross Origin ' jQuery HTML- . AJAX Cross Origin - jQuery Cross Origin AJAX. .

:

   $.ajax({
        crossOrigin: true,
        url: url,
        success: function(data) {
            console.log(data);
        }
    });

: http://www.ajax-cross-origin.com/

-3

All Articles