Ask Your Question
4

What is the method for loading a HTML page from a different domain using jQuery AJAX?

asked 2023-06-10 18:40:46 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-10 19:05:02 +0000

huitzilopochtli gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-10 18:40:46 +0000

Seen: 7 times

Last updated: Jun 10 '23