0

i want to load domain https://api.jqueryui.com/dialog/ with load function or $.ajax function but this give me error :

Access to XMLHttpRequest at 'https://api.jqueryui.com/dialog/' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

here my code:

$("body").load('https://api.jqueryui.com/dialog/');

also tryed this code:

    $.ajax({
        xhrFields: {
            withCredentials: true
        },
        headers:{
            "Access-Control-Allow-Origin": "*"
        },
        crossDomain: true,
        type: "GET",
        url: "https://api.jqueryui.com/dialog/",
    }).done(function (data) {
        $('body').append(data);
    });
  • Are you trying to download the HTML page of the documentation? Just use a hyperlink to redirect or an iframe if it needs to be embedded. Or are you actually trying to use the dialog widget in your project? Then you have to include the widget code in your project, not ajax the documentation. – Shilly Sep 19 '19 at 14:02
  • Read this https://medium.com/@baphemot/understanding-cors-18ad6b478e2b#targetText=Cross-Origin%20Resource%20Sharing%20(CORS)&targetText=CORS%20is%20a%20mechanism%20which,a%20different%20sub%20domain%20(eg. If you want to do CORS request you first need to send request to server with OPTION verb, and you need server to process and response to it, and then do GET request. So basically you need to have server that allow it or have access to server and make some settings changes. – maximelian1986 Sep 19 '19 at 14:03
  • look at [this](https://stackoverflow.com/questions/15005500/loading-cross-domain-endpoint-with-jquery-ajax) – Ahmed Sunny Sep 19 '19 at 15:09

0 Answers0