0

I am trying to load an external file that contains some html code into a div using jQuery.load, but I failed: Div:

<div id="htmhtm"></div>

jQuery:

$('#htmhtm').load(
'https://github.com/kastolom/diefororacle/blob/master/2014-08-28-pivot/html/article.html'
);

JSFiddle

Could anyone please tell me where the problem is?

I want to have my blog entries outside of the blog hosting, in order to be able to migrate from one resource to another, for example, from blogger.com to wordpress

neshkeev
  • 6,280
  • 3
  • 26
  • 47
  • 1
    http://en.wikipedia.org/wiki/Same-origin_policy – Fabrício Matté Aug 27 '14 at 23:19
  • If you look at the console output you'll see something like this: "...not allowed by Access-Control-Allow-Origin." You are running into a [cross site scripting (XSS) issue](http://en.wikipedia.org/wiki/Cross-site_scripting) – dc5 Aug 27 '14 at 23:19
  • 1
    Github is not a CDN and should not be used as such. You should put this file on a server. After that you need to allow [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) on that server (or at least that file). Please note that [CORS is only supported in IE 10+ and all other major browsers](http://caniuse.com/#feat=cors) – Adam Merrifield Aug 27 '14 at 23:19
  • possible dupe of http://stackoverflow.com/q/2453981/1331430 and http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy ? – Fabrício Matté Aug 27 '14 at 23:21

1 Answers1

2

Try

create file , save as type json, e.g., content.json

callback({"result":"<p>something that I need to add</p>"})

js

(function () {
    callback = function (data) {
        if ($(data.result).is("p")) {
            $("#htmhtm").html(data.result)
        }
    };  
    $.getJSON("https://raw.[url]/content.json?callback=?");
}());

jsfiddle http://jsfiddle.net/guest271314/wdg14r02/

guest271314
  • 1
  • 15
  • 104
  • 177