0

I'm messing with jQuery .load()

Here is my code sample:

<html>
  <head>
    <meta charset="utf-8">
    <title>load demo</title>
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
  </head>

  <script>
    $(document).ready(function(){
      $("button").click(function(){
        $("#div1").load('test.txt');
       });
     });
   </script>

   <body>
     <div id="div1">Old text</div>
     <button>Get new text</button>

  </body>
</html>

It doesn't load neither on Safari (OSX) nor on Firefox (Rasperian). I knew this question was asked many times, but no answer did really helped.

Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30
Chrisp
  • 1
  • 2

2 Answers2

1

Your syntax is correct but maybe your file is not fetch from correct location

You should also handle error if any

also check this jquery-load-method

 $(document).ready(function(){
  $("button").click(function(){
    $("#div1").load('/test.txt', function( response, status, xhr ) {
     if ( status == "error" ) {
        alert( "Sorry but there was an error: " + xhr.status + " " + xhr.statusText );
     }
    });
   });
 });
Ravi Makwana
  • 2,782
  • 1
  • 29
  • 41
1

jquery-3.4.1 keypress() event is not triggered for links on firefox at second time. Initially, when screen loads, the event is triggered. Coming back from any other screens to previous screen, it is not triggered.

Cosmin Staicu
  • 1,809
  • 2
  • 20
  • 27
preethi
  • 11
  • 1