admin管理员组

文章数量:1327661

I was building angular's official 'heroes tutorial app' and instead of using their in-memory-data code, i tried using a json.placeholders (users) api so the app would be more real-world example.

Problem is when i change the official codes example url(in-memory-url) with the json.placeholder's api it just doesnt list the names and i checked the chrome dev console-network tab it shows status code 304,

By the way I am only trying to make a get request part of the tutorial, here is the error:

Request URL:
Request Method:GET
Status Code:304 
Remote Address:104.31.87.157:443
Referrer Policy:no-referrer-when-downgrade

Edit:

So i managed to list users from json.placeholder on the app with using observables from rxjs, then i changed it back to promise method official website shows that way and still not listing. Maybe it's something about the angular's promises i dont know.

However browsers network still showing 304 status. I am worrying that this could be a problem and it shouldn't be this way. So any help would be appreciated thanks.

I was building angular's official 'heroes tutorial app' and instead of using their in-memory-data code, i tried using a json.placeholders (users) api so the app would be more real-world example.

Problem is when i change the official codes example url(in-memory-url) with the json.placeholder's api it just doesnt list the names and i checked the chrome dev console-network tab it shows status code 304,

By the way I am only trying to make a get request part of the tutorial, here is the error:

Request URL:https://jsonplaceholder.typicode./users
Request Method:GET
Status Code:304 
Remote Address:104.31.87.157:443
Referrer Policy:no-referrer-when-downgrade

Edit:

So i managed to list users from json.placeholder on the app with using observables from rxjs, then i changed it back to promise method official website shows that way and still not listing. Maybe it's something about the angular's promises i dont know.

However browsers network still showing 304 status. I am worrying that this could be a problem and it shouldn't be this way. So any help would be appreciated thanks.

Share Improve this question edited May 4, 2017 at 14:18 Reşit Körsu asked May 2, 2017 at 20:51 Reşit KörsuReşit Körsu 5983 gold badges9 silver badges18 bronze badges 2
  • 1 This looks like it actually worked better than you would have expected. Can you show us a bit of your code? – DaSourcerer Commented May 2, 2017 at 20:59
  • Related: stackoverflow./a/14117744/3012385 – DaSourcerer Commented May 2, 2017 at 21:05
Add a ment  | 

3 Answers 3

Reset to default 3

HTTP 304 header code means "Not modified", it's not an error. According to the RFC 2616 of HTTP 1.1, the server only sends back headers, not the response which tells the browser to use the response that it had already in cache.

On the other hand, angular will always put 200 in status (even if it is a 304) and you shouldn't have to bother about keeping up to date your data, since you retrieve the fresher value each time (without bothering if it's from a cache in the server or fresh data from the server)

Id Add a random query string behind your url, that takes timestamp as the value. This way, each request will be considered a fresh one

Moreover id refer you to this topic

I was facing this issue in Angular 15. Reason was, I sending blank request to post rest API.

I fixed by sending random number in payload as:

let randomNo=Math.floor(Math.random() * (50 - 1 + 1)) + 1;

let payload= {randomNo:randomNo};

in some cases the cached headers go away by simply ment out the ponent rendered area in index.html file (better to do in the app ponent html file also) and un ment after a page reload

本文标签: javascriptAngular HTTP 39get39 request 304 errorStack Overflow