hi. i would like to ask if it is possible in ajax technology (working with servlets) to get not the whole data from responseText but line by line. i mean when putting in servlet lines of text using println method (response object) i would like to get every seperate line on the client side (for displaying achieving data like in console)
+1
A:
var yourLines = yourString.split("\n");
for (var i = 0, j = yourLines.length; i < j; i++) {
var currentLine = yourLines[i];
/* … */
}
David Dorward
2009-11-05 13:08:55
+1
A:
This is just possible. It more look like that you have trouble with splitting the lines in Javascript. The println() writes to the response with the system default line separator which is usually \r\n
. So if you want to get the separate lines in Javascript, you need to split
the responseText
on \r\n
to get an array
of lines.
BalusC
2009-11-05 13:10:15
+1
A:
The AJAX responses are sent as a single unit from the server to the client - so no, you cannot read them in real-time (as and when the server side code calls println). But you can easily emulate it by splitting the response string at new lines - response.split("\n")
- and iterating through the resulting array.
Amarghosh
2009-11-05 13:18:48