AJAX call is STUPID [.SOLVED]

I dont know if i was wrong or XMLHttpRequest is STUPID. My random quote machine just go to https://quotesondesign.com/api-v4-0/ to get 1 same JSON object everytime when i send request to the API
Here is my javascript code.

var text_receive = document.getElementById(“quote-text”);
var btn= document.getElementById(“more”);

    btn.addEventListener('click',function(e){
    var ourRequest = new XMLHttpRequest();
    
    ourRequest.open('GET','http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',true);
    
    ourRequest.onload = function(){
    var Data = JSON.parse(ourRequest.responseText);
        console.log(Data);
       text_receive.insertAdjacentHTML("beforeend",Data[0].content);
    }
    
    //send request
    ourRequest.send();
      //  num++;
   // alert(num);
    </code>

and here is the link to my project http://codepen.io/Fatherof10kids/pen/WpamJK.

Please help me!!! i am desperate!

I think cache is the reason why i deal with same JSON data received. Pls help!

Just add ‘?nocache=’ + (new Date()).getTime() to your URL link and your problem solves

Oh thanks alot for your answer

Is everything you don’t understand stupid?

2 Likes

LOL, yep. btw the solution i 've found is adding ‘?nocache=’ + (new Date()).getTime() is suitable for this situation? or has another better way?