0
    if (xhr.status === 200) {
        alert(xhr.responseText+document.getElementById("thatid").value);
        document.getElementById("thatid").value = xhr.responseText;
        //document.getElementById("f3").value = 'yayayay';
    }

<form>
<button id="thatbtn" value="submit" >
<input type="hidden" id="thatid" value="bob" >
</form>

basically the alert works and prints xhr.responsetext, but it does not change the 'thatid' input on form

<div id="f5" style="display:none;"></div>

xhr.onload = function() {
    if (xhr.readyState === 4 && xhr.status === 200) {
        dude = xhr.responseText;
        f5.innerHTML = dude;
        alert(dude+f5.innerHTML);
         //this does change the innerHTML
         //however, trying to read f5.innerHTML outside of onload
          //function will read '' or none, y not persistent?
    }
    else if (xhr.status !== 200) {
        alert('Request failed.  Returned status of ' + xhr.status);
    }
};

alert(f5.innerHTML); //yields no text

Edo Edo
  • 164
  • 2
  • 9
  • You will need to show more code (javascript). – Ivan86 Dec 08 '19 at 18:15
  • 1
    You need to check for `readyState === 4`. Something like this: `if (xhr.readyState === 4 && xhr.status === 200)`. – Danny Fardy Jhonston Bermúdez Dec 08 '19 at 18:45
  • tried it, still weird bug, it seems changing any DOM info during the xhr.onload() function is not persistant, i can change DOM before or after this function, but not IN it where I can retrieve it outside it... – Edo Edo Dec 08 '19 at 20:38
  • You're trying to retrieve it **before** the response has loaded, triggered the `load` event, run the function, and set it. – Quentin Dec 08 '19 at 20:43
  • my question is about editing the DOM, xhr.responsetext comes back just fine. can you explicate your comment quentin? are you saying i need to check for it in a DOM.onload() function? how so? – Edo Edo Dec 08 '19 at 20:46

0 Answers0