To load a HTML page from a different domain using jQuery AJAX, you need to use JSONP (JSON with Padding) which is a technique for loading data asynchronously from a different domain using a script tag instead of XHR. Here's an example code:
$.ajax({
url: "http://example.com/page.html",
dataType: "jsonp",
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.log(error);
}
});
Note that the server you are loading the HTML from must support JSONP by wrapping the response in a callback function.
Asked: 2023-06-10 18:40:46 +0000
Seen: 7 times
Last updated: Jun 10 '23