-1

I'm trying to load html content cross-domain using ajax. Here is my code:

$.ajax({
            crossDomain: true,
            crossOrigin: true,
            url: 'http://en.wikipedia.org/wiki/Cross-origin_resource_sharing',
            type: "GET",
            dataType: "JSONP",
            success: function (data) {
                $("#divTest").html(data);
            },
            error: function (e) {

            }

        });

#divTest is a <div>, but ajax always returns empty data with no error message. I tried setting crossOrigin, crossDomain properties as suggested, but without success. Can someone look and let me know what I'm missing ?

Also: is there any better and secure way to load html content cross-domain?

Update: After implementing the latest jQuery, it gets status code 200 and thinks of it as success.

Sainan
  • 1,274
  • 2
  • 19
  • 32
AshishJindal
  • 176
  • 2
  • 10

2 Answers2

0

I got a little workaround with Cross-Domain-Stuff:

Request a PHP File and let it download the Content for you:

./dl.php?url=http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Because Webpages give out there Content, but don't like it Framed or by Ajax.

The PHP Script is as simple as:

<?=file_get_contents($_GET["URL"]); ?>

Of course you may add to this, but it'll work too.

Sainan
  • 1,274
  • 2
  • 19
  • 32
0

Did you tried with getJSON method of jquery Ajax, here are some examples

But your server should also allow cross domain

Community
  • 1
  • 1
gurvinder372
  • 66,980
  • 10
  • 72
  • 94