title: Javascrpit AJAX: Problems with Get Method (using Web-Api Core)
body: <p>I have problems doing a simple ajax method and I have zero idea how to do it since most of my work was done by tutorials that don't explain the backend part of their app and don't have good examples.</p>
  <p>I want to show a message from my backEnd and also want to put some text and show also a message with that text</p>
  <p>I'm using html/css/javascript</p>
  <p>HTML Part (Will be my UI)</p>
  <pre><code>        &lt;template id=&quot;checkHello&quot;&gt;
              &lt;h3 class=&quot;hello&quot;&gt;{{ hello }}&lt;/h3&gt;
          &lt;/template&gt;
  
          &lt;template id=&quot;checkType&quot;&gt;
              &lt;h2&gt;Type Something:&lt;/h2&gt;
              &lt;div id=&quot;Type_1&quot;&gt;
                  &lt;input type=&quot;text&quot; id=&quot;edit type&quot; placeholder=&quot;Type here something&quot; /&gt;
                  &lt;button id=&quot;type_s&quot;&gt;Check&lt;/button&gt;
                  &lt;h2 class=&quot;type&quot;&gt;{{ type }}&lt;/h2&gt;
              &lt;/div&gt;
          &lt;/template&gt;
  
      &lt;!-- Here I have other code that works perfect--&gt;
      
      &lt;script src=&quot;https://code.jquery.com/jquery-3.5.1.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/site.js&quot; asp-append-version=&quot;true&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.js&quot;&gt;&lt;/script&gt; 
  
  </code></pre>
  <p>I also try something more simple but it didn't work</p>
  <pre><code>&lt;div id=&quot;users_B&quot;&gt;
          
      &lt;/div&gt;
  
      &lt;div id=&quot;users_C&quot;&gt;
          &lt;input type=&quot;text&quot; id=&quot;type&quot; placeholder=&quot;Type here something&quot; /&gt;
          &lt;button id=&quot;type_s&quot;&gt;Check&lt;/button&gt;
      &lt;/div&gt;
  
  &lt;!-- Here I have other code that works perfect--&gt;
      
      &lt;script src=&quot;https://code.jquery.com/jquery-3.5.1.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;js/site.js&quot; asp-append-version=&quot;true&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.js&quot;&gt;&lt;/script&gt; 
  
  </code></pre>
  <p>Javascript (here i have a little trouble and maybe my problem is here (where? idk))</p>
  <pre><code>
  $(function b() {
  
      var $users_B = $('#users_B');
      var $users_C = $('#users_C');
  
      var $hello = JSON.stringify($('#hello'));
      var $type = JSON.stringify($('#type'));
  
      var myUser = $('#checkUser').html();
      var myHello = $('#checkHello').html();
      var myType = $('#checkType').html();
      
      function checkHello(arroz_1) {
          $users_A.append(Mustache.render(myHello, arroz_1));
      }
  
      function checkType(arroz_2) {
          $users_A.append(Mustache.render(myType, arroz_2));
      }
      
      //-------------Hello-----------------------
      //debugger;
      //Just Here gives me error 400 idk why, not makes sense at all
      $.ajax({
          contentType: 'application/json; charset=UTF-8',
          url: uri_hello,
          type: 'GET',
          dataType: 'json',
          beforeSend: function (request) {
              request.setRequestHeader(&quot;Authorization&quot;, 'Bearer ' + localStorage.getItem(&quot;key&quot;));
          },
          //this should return a simple string from de backEnd
          success: function (data1) {
              $.each(data1, function (i, arroz_1) {
                  //checkHello(arroz_1);
                  $users_B.append('&lt;h3&gt;' + arroz_1 + '&lt;/h3&gt;');
              });
          },
          error: function (xhr, textStatus, errorThrown) {
              //gives me error but dont shows the error, shows something like this [Object: object]
              console.log('XHR:' + JSON.stringify(xhr) + '\nTextStatus:' + JSON.stringify(textStatus) + '\nErrorThrown:' + JSON.stringify(errorThrown));
          }
      });
  
      //-------------Type-----------------------
      //This is Now the Problem, thu button doesn't work at all idk why
      $users_C.delegate('.type_s', 'click', function () {
  
          $.ajax({
              contentType: 'application/json; charset=UTF-8',
              url: uri_Type,
              type: 'GET',
              dataType: 'json',
              beforeSend: function (request) {
                  request.setRequestHeader(&quot;Authorization&quot;, 'Bearer ' + localStorage.getItem(&quot;key&quot;));
              },
              success: function (data2) {
                  $.each(data2, function (i, arroz_2) {
                      //checkType(arroz_2);
                      $users_C.append('&lt;h3&gt;' + arroz_2 +'&lt;p&gt;' + $type + '&lt;/p&gt;&lt;/h3&gt;');
                  });
              },
              error: function (xhr, textStatus, errorThrown) {
                  console.log('XHR:' + JSON.stringify(xhr) + '\nTextStatus:' + textStatus + '\nErrorThrown:' + errorThrown);
              }
          });
      });
  }
  
  
  </code></pre>
  <p>HttpGet Methods</p>
  <pre><code>[HttpGet(&quot;HelloWorld&quot;), Authorize] //helloReply is a string         //null 
          public async Task&lt;ActionResult&lt;HelloReply&gt;&gt; Hello([FromQuery] Empty_2 empty_2)
          {
              var hello = await _greetClient.SayNormalHelloAsync(empty_2);
  
              return Ok(hello);
          }
  
          [HttpGet(&quot;TypeSomething&quot;), Authorize]                       //string
          public async Task&lt;ActionResult&lt;HelloReply&gt;&gt; Type([FromQuery] HelloRequest empty_2)
          {
              var hello = await _greetClient.SayHelloAsync(empty_2);
    
              return Ok(hello);
          }
  
  </code></pre>
  <p>GreeterService.cs</p>
  <pre><code>
  public override Task&lt;HelloReply&gt; SayNormalHello(Empty_2 request, ServerCallContext context)
          {
              return Task.FromResult(new HelloReply
              {
                  Message = &quot;Good Morning User, I hope you have a Good Day&quot; 
              });
          }
  
          public override Task&lt;HelloReply&gt; SayHello(HelloRequest request, ServerCallContext context)
          {
              return Task.FromResult(new HelloReply
              {
                  Message = &quot;You Type this:&quot; + request.Name
              });
          }
  
  
  
  </code></pre>
  <p>This is what the User Need to See</p>
  <p><a href="https://i.stack.imgur.com/XECGo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XECGo.png" alt="enter image description here" /></a></p>
  <p>So in the Message 1 will show the Greeter.cs message &quot;Good Morning User, I hope you have a Good Day&quot;</p>
  <p>In the second message if I write the word &quot;hello&quot; in the input, and if I click on the button afterwards, the message that has to appear is this &quot;You Type this:Hello&quot;</p>
  <p>So my question is: Whats is wrong with this? Is is the javascript Ajax Method? How to do it without destroying the part I have correct in HTML? Is there other way to do this without javascript and using the html file I have?</p>
  <p>Any help is welcome.</p>
  <h2>Edit:</h2>
  <p>Now my problem is just in message 2, the old problem I need to change de [FromBody] to [FromQuery] and the url works fine. The first Message shows correct the string from the Greeter.cs, now my problem is getting data from that input and the button don''t work idk why.</p>