title: Use AJAX and jQuery with WordPress
body: <p>I'm trying to get <a href="https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_ajax_ajax" rel="nofollow noreferrer">this W3 Schools example</a> to work in WordPress.</p>
  
  <p>I already tried this in function.php:</p>
  
  <pre><code>function hook_ajax_script(){
          wp_enqueue_script( 'my_ajax_script', get_bloginfo('template_url')."/rscripts/robajax.js" );
      }
      add_action( 'wp_enqueue_scripts', 'hook_ajax_script' );
      add_action( 'admin_enqueue_scripts', 'hook_ajax_script' );
  
  add_shortcode( 'ajax1', 'ajax1_shortcode' );
      function ajax1_shortcode( $args ) {
      ?&gt;
      &lt;div id="demo"&gt;
      &lt;h1&gt;The XMLHttpRequest Object&lt;/h1&gt;
      &lt;button type="button" onclick="loadDoc()"&gt;Change Content&lt;/button&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>and my Script</p>
  
  <pre><code>jQuery(document).ready(function(){
    jQuery("button").click(function(){
          jQuery.ajax({url: "rob.txt", success: function(result){
              $("#div1").html(result);
          }});
      });
  });
  </code></pre>
  
  <p>When I click the Button I get 404 "rob.txt" not found.</p>
  
  <p>I tried it also to do it with a Plugin and rob.txt was inside.</p>
  
  <p>How to get this example to work?</p>