1

Hi to all i want to ask something about wordpress api!

I have one button in my vue when clicked fire a function who run an axios get request and fetch me the value of one field in specifiec post!

handleController(){
        axios.get('https://nice-ardinghelli.185-4-133-211.plesk.page/admin/wp-json/wp/v2/teams/'+this.team.id)
        .then(response => {
        this.isControllerSet = response.data.acf.acf_team_controller
        console.log(this.isControllerSet)
        })
    },

Here is the wordpress backend

Backend wordpress

And here is the console.log result if i hit the button

Console.log

The problem is:

  1. When wordpress backend user update the value of the field the vue app don't fetch me the new value until i hit ctrl + f5. If i hard refresh i get the new value. How can i fetch always the new value when button clicked without hard refresh?

Here is the wordpress user update the value

enter image description here

And here is the console.log result if i hit the button

Console.log

  1. When i POST data with axios and update this field it happens the same as above i don't get the fresh data until i hard refresh(CTRL + F5) my vue app
Tsourou Nas
  • 43
  • 2
  • 9
  • Do you mean that you're getting stale data from the `axios.get()` command? – Terry Jan 31 '22 at 20:17
  • If i don't hard refresh i can't get the updated value! I want always get updated value from wordpress backend! I get stale data until ctrl F5 but i cant ask the user to ctrl F5 to get updated data! – Tsourou Nas Jan 31 '22 at 20:42
  • Check your network tab. Are you sure you’re getting updated payloads from your endpoint? Or is axios somehow caching them for you? – Terry Jan 31 '22 at 21:25
  • I cant explain that! If i hit the endpoint and change the value of the field in wordpress administrator panel i get updated value! If i get axios in the endpoint didnt get the updated value! I really can't figure out what happen? I want when user click the button to see if controller is set or no? – Tsourou Nas Jan 31 '22 at 21:37
  • You didn’t answer my previous question. What does the network tab say? I’m not asking you to explain what happened. Just questions that’ll help with troubleshooting. – Terry Jan 31 '22 at 22:16
  • When i click the button and go to network i get 200 OK response but the data is not changed! – Tsourou Nas Feb 01 '22 at 07:43
  • What is the response in the network? Does it show the updated value? Otherwise it's an issue with the WP backend and not client side (I have a feeling it is the former). – Terry Feb 01 '22 at 07:46
  • What i see is that the first time axios load the data but the other time i call axios to get data fetch it from disk cache! And of course without updated value – Tsourou Nas Feb 01 '22 at 07:56
  • So that is your problem. Axios is caching your fetches. – Terry Feb 01 '22 at 08:12
  • Is there a way to Bypass this or always axios fetch data from disk cache! – Tsourou Nas Feb 01 '22 at 08:15
  • See answers here: https://stackoverflow.com/questions/49263559/using-javascript-axios-fetch-can-you-disable-browser-cache. This question is essentially a duplicate of that. – Terry Feb 01 '22 at 08:16

0 Answers0