0

onreadystatechange() gets called 3 times. the second time 'results-div'.innerhtml is set to 'empty' and then erased on the last call to the function. also, does jquery handle ajax browser compatibility?

function loaddata(){ 
        var res = new XMLHttpRequest();
        res.onreadystatechange=function(){
            alert('change'); //for debug
            if(res.readyState == 4 && res.status==200){
                document.getElementById('results-div').innerHTML = res.response;
                }
            else{
                alert('nothing'); //for debug
                document.getElementById('results-div').innerHTML = '<p> empty </p>';
                }
        }
        res.open('GET', '?search=' + value);
        res.send();
}

'results-div'.innerHTML erased on the last call. if(must be true) 'results'.innerHTML = res.response = ''

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
nf071590
  • 1,170
  • 1
  • 13
  • 17
  • 1
    It should be `res.responseText` or `res.responseXML` depending on the MIME type of the response – devnull69 Apr 10 '14 at 13:26
  • 1
    `XMLHttpRequest.response` depends on `XMLHttpRequest.responseType`, which you did not set. – Musa Apr 10 '14 at 13:37
  • changed to responseText, still does not work correctly @devnull69 – nf071590 Apr 10 '14 at 14:35
  • did you check the browser development tools of your choice (Chrome dev tools, Firebug etc) to find out what is actually going on with the request? – devnull69 Apr 10 '14 at 15:55

0 Answers0