javascript - Segmenting AJAX responses in perl CGI? -
For a Perl CGI script, is it possible for many different HTTP reactions in your AJAX response segment?
Say I have this code:
xmlhttp = new XMLHttpRequest (); Xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate == 4 & xmlhttp.status == 200) {onDataReceived (xmlhttp.responseText); } And if (xmlhttp.status! = 200 & xmlhttp.status! = 0) {}} xmlhttp.open ("post", "script.cgi", is true); Xmlhttp.setRequestHeader ("content-type", "application / x-www form-urlencoded"); Xmlhttp.send (toURLString (option));
Javascript (I do not tell about issues of XML object compatibility, I know, and do not care).
And this:
print "content-type: text / html \ n \ n"; My% form = wars (); If ($ ENV {REQUEST_METHOD} ACCUP "POST") {$ | = 1; (My $ i, (1..100000000)) {print "1 \ n"; }}
As perl CGI Is it possible to print this result, instead of making 100,000,000 ss in many different packets of 1S before output at the end?
Please see such questions for potential approaches, though this is not peel-specific:
From the linked wiki article, this link looks most relevant:
However, the "server push" that you are considering, Instead, you will strongly suggest to consider a voting approach :
The server stores part of the data as accessible files (some come Country meta information)
print "location: xxxx"; # Sorry, the exact location of the HTTP response was forgotten # The location URL is mapped to /home/htdocs/webdocs/tmp/chunk_0.html My% form = Vars (); If ($ ENV {REQUEST_METHOD} ACCUP "POST") {$ | = 1; $ File_num = 0; My $ FH; For (my $ i, (1..100000000)) {If ($ i% 1000 == 0) {$ $ Close FH $ FH; Open $ FH, "& gt;", / home / htdocs / webdocs / tmp / chunk_ $ {file_num} .html "; Adding General Error Handling at # Open / Close I'm too lazy to type file_num ++; } $ $ FH "1 \ n"; } $ FH Print "\ n ############## END_TRANSMISSION__LAST_FILE #################### \" "; # This was a particularly dumb method of marking the EOF, but you get close to $ FH drift; }
AJAX polar receives one after another in a loop, moves the reaction forward and is looking for meta-information to know that (and if ) Is for voting in the next election.
Comments
Post a Comment