title: Run Axios on AngularJs button click
body: <p>I'm working with AngularJs and Bootstrap. What i need is to make post on an API that have an app key and app token. First i've tried with ajax, but i get an 405 response:</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at
    '<a href="https://thelink" rel="nofollow noreferrer">https://thelink</a>'
    from origin '<a href="http://mylink" rel="nofollow noreferrer">http://mylink</a>' has been blocked by
    CORS policy: Response to preflight request doesn't pass access control
    check: No 'Access-Control-Allow-Origin' header is present on the
    requested resource.</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>       $scope.sendThis = function(){
          var destinyData = {
              "FieldId": 1,
              "Name": "Test",
              "Text": "Test",
              "IsActive": true,
              "Position": 105
          };
  
          $.ajax({
              url: 'thelink',
              headers: {
                  'Content-Type': 'application/json',
                  'API-AppKey': 'thekey',
                  'AppToken': 'thetoken'
              },
              data: destinyData,
              success: function(result){
                  console.log(result);
              },
              error: function(){
                  console.log("Something's wrong!");
              }
          });
      }
  </code></pre>
  
  <p>And my HTML view:</p>
  
  <pre><code>&lt;button type="button" class="btn btn-primary" ng-click="sendThis()"&gt;Send&lt;/button&gt;
  </code></pre>
  
  <p>Then i read that i can use Axios to make the request on my backend. So, i installed the axios library (<code>npm axios</code>) and tested:</p>
  
  <pre><code>const axios = require('axios');
  
  axios({
      method: 'post',
      url: 'thelink',
      headers: {'Content-Type': 'application/json', 'API-AppKey': 'thekey', 'AppToken': 'thetoken'},
      data: {
          "FieldId": 113,
          "Name": "Test",
          "Text": "Test",
          "IsActive": true,
          "Position": 545
      }
  })
  .then(function(response){
      console.log(response);
  })
  .catch(function(error){
      console.log(error);
  })
  </code></pre>
  
  <p>And it works! Now my question: how can i trigger the method post of Axios on a button click, just like my first test (<code>$scope.sendThis</code>)?</p>
  
  <p>And a second question: there's a way to generate an api with express to call the axios example on NodeJs?  </p>
  
  <p>Hope you can help me. Thanx in advance.</p>
  
  <p>I'm using Javascript, AngularJs, Bootstrap and NodeJs</p>