title: WordPress Custom Plugin button onclick call php function
body: <p>My plugin shows 2 input fields and a button wherever you put the placeholder in WP. After clicking the button it calls a js function which should start a php function using AJAX but somehow i get the error message: "reference error myAjax is not defined"</p>
  
  <p>wsn-plugin.php</p>
  
  <pre><code>function wpb_new_company(){
      echo '&lt;input type="text" class="form-control" id="companyName" placeholder="Firmenname"&gt;';
      echo '&lt;input type="text" class="form-control" id="companyYear" placeholder="Jahr"&gt;';
      echo '&lt;button onclick="myAjax();" id="btnNewCompany" type="submit" class="btn btn-primary"&gt;Erstellen&lt;/button&gt;';
  }
  </code></pre>
  
  <p>script.js (which handles all the events)</p>
  
  <pre><code>function myAjax() {
      alert("myAjax gestartet");
        $.ajax({
             type: "POST",
             url: 'localhost/wp/wp-content/plugins/wsn-plugin/wsn-plugin.php',
             data:{action:'call_this'},
             success:function(html) {
               alert(html);
             }
  
        });
        alert("myAjax ausgeführt");
   }
  </code></pre>
  
  <p>and again wsn-plugin.php which should then run some function</p>
  
  <pre><code>if($_POST['action'] == 'call_this') {
      echo "i reached it";
  }
  </code></pre>
  
  <p><strong>Changed</strong> </p>
  
  <pre><code>function wpb_adding_scripts() {
  wp_register_script('wsn_script', plugins_url('script.js', __FILE__), array('jquery'),'1.1', true);
  wp_enqueue_script('wsn_script');
  }
  add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
  </code></pre>
  
  <p>and js script:</p>
  
  <pre><code>function myAjax() {
      alert("myAjax gestartet");
        $.ajax({
             type: "POST",
             url: '/wp/wp-content/plugins/wsn-plugin/wsn-plugin.php',
             data:{action:'call_this'},
             success:function(html) {
               alert(html);
             }
  
        });
        alert("myAjax ausgeführt");
   }
  </code></pre>
  
  <p>no chrome shows the error message:
  localhost says <br /> fatal error uncaught error call to undefined function add_action() in wsn-plugin.php:16</p>