javascript - XMLHttpRequest does not seem to do anything -
i have been trying unsuccessfully download binary file server using jquery-ajax, gave up. trying use xmlhttprequest instead. however, cannot simple example working.
strangely enough, code not appear anything. copy/pasted w3schools , example near identical many other examples. not work me in either chrome or ff:
var xhttp = new xmlhttprequest(); xhttp.onreadystatechange = function() { if (xhttp.readystate == 4 && xhttp.status == 200) { // action performed when document read; } }; xhttp.open("get", '/blah/blah/output.png', true); xhttp.send(); we go onreadystatechange function once, on open() statement xhttp.readystate equal one, not on send() step. should think @ least throw kind of error rather nothing @ all.
also, experiment, purposely fed open() bad url - again no reply.
can tell me might doing wrong?
thank much.
your code looks correct me, points external cause.
is code flowing way through end of execution context? browsers hold onto network requests until engine yields browser.
for instance:
var xhttp = new xmlhttprequest(); xhttp.onreadystatechange = function() { if (xhttp.readystate == 4 && xhttp.status == 200) { // action performed when document read; } }; xhttp.open("get", '/blah/blah/output.png', true); xhttp.send(); while(true){} will never send call.
Comments
Post a Comment