jQuery html with load()

Asked

Viewed 337 times

1

I am trying to use this Jquery function but it is not working properly because it shows me nothing.

<script>
$("#minha_div").load("Noticias.html");
</script>

 <div id="minha_div" width="550" height="400"  style="position: absolute; left: 1%; top: 39%;"></div>

On the console appears:

Xmlhttprequest cannot load. (File path) Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https, Chrome-Extension-Resource.

  • The error message itself already says: you should add the protocol, full path, for example: "http://seusite.com/Noticias.html"

  • Correct, but for example now I am testing only on the computer an offline page. There is a way to see the page?

  • Straight from the file system, no server, do not know if it works with the function load(). I really can’t tell you:(

  • That div later I can change the size to look like an iframe?

  • putting this div first and this script later would not be correct?

  • Loading vis script files from the local computer is not allowed for security reasons. Imagine what someone could read by giving them a simple HTML!

Show 1 more comment

1 answer

1

Use jQuey Ajax:

$.ajax({ 
     url: "Noticias.html", dataType: "html" 
}).done(function( responseHtml ) {
     $("#minha_div").html(responseHtml);
});
  • https://jsfiddle.net/ksodxzwp/ ?

  • 1

    @Chrisadler in jsfiddle will not work, test on your machine where you have the script, replace the code there with the one I posted above, remembering that the file "Noticias.html" has to be in the same folder where the script is executed.

  • I already tested it and it’s not working. I used the Script inside and outside of Head and I can’t

  • @Chrisadler error? Check with the browser inspector if there is an error in javascript.

  • Xmlhttprequest cannot load file://C:/Users/user/Desktop/TESTE/Noticia.html. Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https, Chrome-Extension-Resource. Could that be? <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

  • I was able to show using Http:// . But now the page appears with the original size. there is a way to control this?

  • 1

    @Chrisadler css.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.