Reputation: 133
I would preciate if someone could help me to get the code below to work. The goal is to read the content of a web page and display it in a div that is called #content. What could be wrong?
function content(){
$.ajax({
url : “page.html”,
success : function (data) {
$(“#content”).html(data);
}
});
}
Upvotes: 1
Views: 100
Reputation: 43823
The page that includes the script must be loaded from a web server otherwise you will be seeing XMLHttpRequest cannot load xxx.html. Origin null is not allowed by Access-Control-Allow-Origin
style errors. Cross-site requests like this are not allowed (be default) due to security concerns, although they are possible.
If you serve your test page from a web server, the request will be allowed. Most modern browsers include a JavaScript or Error console that detail errors of this kind.
Upvotes: 0