title: Trouble getting JSON response from API in C# MVC
body: <p>I'm currently struggling trying to get a simple response client-side from my MVC API method.
  Here is my C# Controller Class:</p>
  
  <pre><code>public class LogController : ApiController
  {
  
      private static ConcurrentBag&lt;StreamWriter&gt; clients1;
      private static Random random;
      private static Timer timer;
  
      static LogController()
      {
          clients1 = new ConcurrentBag&lt;StreamWriter&gt;();
          clients2 = new ConcurrentBag&lt;StreamWriter&gt;();
  
          timer = new Timer();
          timer.Interval = 1000;
          timer.AutoReset = true;
          timer.Elapsed += timer_ElapsedY1;
          timer.Start();
  
          random = new Random();
  
      }
  
      private async static void timer_ElapsedY1(object sender, ElapsedEventArgs e)
      {
          var price = 1.0 + random.NextDouble(); // random number between 1 and 2
  
          foreach (var client in clients1)
          {
              try
              {
                  var data = string.Format("data: {0}\n\n", price);
                  await client.WriteAsync(data);
                  await client.FlushAsync();
              }
              catch (Exception)
              {
                  StreamWriter ignore;
                  clients1.TryTake(out ignore);
              }
          }
      }
  
      [EnableCors(origins: "http://localhost:50322", headers: "*", methods: "*")]
      [HttpGet]
      public HttpResponseMessage GetY1(HttpRequestMessage request)
      {
          var response = request.CreateResponse();
          response.Content = new PushStreamContent((a, b, c) =&gt;
          { OnStreamAvailableY1(a, b, c); }, "text/event-stream");
          return response;
      }
  
  
      private void OnStreamAvailableY1(Stream stream, HttpContent content,
          TransportContext context)
      {
          var client = new StreamWriter(stream);
          clients1.Add(client);
      }}}
  </code></pre>
  
  <p>In my client I'm simply trying to do:</p>
  
  <pre><code>  $.ajax({
      type: "GET",
      url: "http://localhost:56495/api/Log/GetY1",
      dataType: 'json',
      success: function (data) {
          alert(data);
      },
      error: function (msg) { alert('error')}
  });
  </code></pre>
  
  <p>I've first faced the problem related with enabling CORS and now I no longer get any error related with allowing acess to the API from the localhost however now I do not get any sort of result from the ajax request whatsoever. I'm trying to figure what I'm doing wrong but so far left without any more clues.</p>