Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS $http not sending GET request
    primarykey
    data
    text
    <p>In an Angular JS app I'm working on, I am using a service to periodically (in a <code>$timeout</code>) make a GET request to a URL in my API (both the Angular app and the API are being served from port 5000 on localhost).</p> <p>For some reason, it appears that $http is not actually sending the GET. For each <code>$http.get()</code>, the <code>.error()</code> is called with empty data and a status of 0. When I check in my server log (I'm running a Ruby on Rails backend with the Unicorn gem for my server), it appears that the server never receives the request from Angular.</p> <p>Here's the function in my service:</p> <pre><code>updateUserStatus = () -&gt; $http.get('/api/v1/status').success (statusData) -&gt; # update the variable and notify the observers this.userStatus = statusData notifyObservers() startStatusTimeout() .error (error, status) -&gt; # if there's an error, log it console.log 'error:' console.log error console.log status startStatusTimeout() </code></pre> <p>What's really odd is that it only happens <em>sometimes</em>. When it stops working, I can change the URL in the <code>$http.get()</code> to <code>'/api/v1/status.json'</code>, and it works. For a while. Then I switch it back and it works again, for a while... obviously there is some greater issue at play.</p> <p>I've been racking my brain for a few days now, and I've seen a bunch of similar issues on SO, but they all seem to be solved with implementing CORS in Angular, which I don't think is applicable to my situation because it's all coming from <code>localhost:5000</code>. Am I wrong? What's going on?</p> <p>For reference, I'm using Angular version 1.0.7.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload