Currently experimenting with
- Redis
- Webdis
- Dart
Here's my code snippet
#import('dart:html');
#import('dart:json');
class ChatClient {
XMLHttpRequest listener;
int parsePosition = 0;
void connect(){
this.listener = new XMLHttpRequest();
this.listener.open("GET", "http://i.target.co.uk:9005/subscribe/test.json", true);
this.listener.setRequestHeader('Accept', 'application/json');
this.listener.on.readyStateChange.add(handleData);
this.listener.send();
}
void handleData(Event event){
print(this.listener.responseText);
/*
if (this.listener.responseText != ""){
Map data = JSON.parse(this.listener.responseText);
print(data["subscribe"]);
}
*/
}
}
void main(){
ChatClient client = new ChatClient();
client.connect();
document.query('#status').innerHTML = 'Loaded!';
}
Encountering an issue where the responseText keeps growing infinitely like
{"subscribe":["subscribe","test",1]}
{"subscribe":["subscribe","test",1]}{"subscribe":["message","test","e"]}
{"subscribe":["subscribe","test",1]}{"subscribe":["message","test","e"]}{"subscribe":["message","test","e"]}
How can I clear or flush the responseText to avoid parsing issues?
Edit: Tried iterating or tracking string length, hoping for a cleaner solution.
Edit: Output of new print statements
readyStat: 2 status: 200
{"subscribe":["subscribe","test",1]}
readyStat: 3 status: 200
{"subscribe":["subscribe","test",1]}{"subscribe":["message","test","e"]}
readyStat: 3 status: 200