Doubt with Jquery Load

Asked

Viewed 268 times

1

I have a menu that I will use on all pages, so I want to upload the content:

I’m doing like this:

<head>
    <meta charset="utf-8">
    <!-- This file has been downloaded from Bootsnipp.com. Enjoy! -->
    <title> </title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="./css/bootstrap.min.css" rel="stylesheet">
     <link href="./css/estilo.css" rel="stylesheet">
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <link rel="icon" href="./favicon/favicon.png">

    <script>
      $("#menu").load("menusistema.html");
    </script>

</head>

<body">

    <div id="menu"></div>

</body>

You’re not carrying anything, which could be wrong?

inserir a descrição da imagem aqui

  • It may be that one of your files uploaded on <script></script> is in trouble or you are not linking right, then the file does not load.

  • I have tried several options and does not load

  • Open your browser console, edit the question, and paste the errors that the console displayed on your page into it.

  • @Guilhermenascimento, I added the image, see if you can help me

  • 1

    No need to post photo, just have copied the error and pasted in the question. Read: Manual on how NOT to ask questions and Do not post your code or your error message

  • @Guilhermenascimento, then the error and why is HTML not inside a web server? that error message only appeared because I tried to call the html in the console, the more the screen goes blank when it opens.

  • @itasouza yes, that’s what I said in the reply, Xmlhttprequest (aka ajax) only works on HTTP and HTTPS servers or extensions to Chrome and firefox.

Show 2 more comments

2 answers

2

Ajax doesn’t work in protocol file://, have to use a server HTTP like Apache or Ngnix, the message itself says this:

Xmlhttprequest cannot load file://... Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https, Chrome-Extension-Resource.

Translating:

Xmlhttprequest cannot load file://... cross source requests ("different" origins) are only supported by protocols: http, data, Chrome, Chrome-Extension, https and Chrome-Extension-Resource.

As I explained in:

And here’s an explanation of what Wamp, Xampp and so on is:

So if you use PHP you can install:

If you use Asp.net-mvc then create a project by VS and port your . html there.

0

uses like this

 <script>
        $(document).ready(function(){
      $("#menu").load("menusistema.html");
        });
    </script>

instead of your

<script>
      $("#menu").load("menusistema.html");
    </script>

and as the friend above said, you need to use a local server, I use xampp, not the local directory, so it works right

Browser other questions tagged

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