javascript - XmlHttpRequest.responseText while loading (readyState==3) in Chrome -
i trying "streaming" (from server client) in javascript ajax (by xmlhttprequest (=xhr). using modified handleresponse function described in cross-browser implementation of "http streaming" (push) ajax pattern
function handleresponse() { if (http.readystate != 4 && http.readystate != 3) return; if (http.readystate == 3 && http.status != 200) return; if (http.readystate == 4 && http.status != 200) { clearinterval(polltimer); inprogress = false; } // in konqueror http.responsetext null here... if (http.responsetext === null) return; while (prevdatalength != http.responsetext.length) { if (http.readystate == 4 && prevdatalength == http.responsetext.length) break; prevdatalength = http.responsetext.length; var response = http.responsetext.substring(nextline); var lines = response.split('\n'); nextline = nextline + response.lastindexof('\n') + 1; if (response[response.length-1] != '\n') lines.pop(); (var = 0; < lines.length; i++) { // ... } } if (http.readystate == 4 && prevdatalength == http.responsetext.length) clearinterval(polltimer); inprogress = false; }
with php script, flushes me data (without ajax flushes data browser while progressing)
i have no problem in firefox, google chrome , ie give me empty responsetext while xhr.readystate equals 3. found problem described in internet, didn't give me solution.
do know, how pass implementation problem in chrome? (w3c says, responsetext can't null in readystate==3 - chrome implemented rule, gives empty string)
and if don't know, know working solution in products? (opensource frameworks, librararies etc.)
thanks lot ideas.
edit: workaround in creating iframe, call script iframe , flush data here , grab data javascript iframe. not ajax solution. see pure ajax solution.
chrome has bug populate xhr.responsetext after number of bytes has been received. there 2 ways around this,
set content type of return "application/octet-stream"
or
send prelude of 2kb prep handler.
either of these methods should make chrome populate responsetext field when readystate == 3.
ie7/8 on other hand can't it, need resort long polling or use cross domain trick xdomainrequest in ie8, la ms
Comments
Post a Comment