Splitting xmlhttp.responseText row by row?
How can I split up xmlhttp.responseText I receive from a database select row by row? My database layout contains 3 columns which I want to hand over to a function.
This is what the responsetext looks like:
75px, 218px, foo, 12px, 13px, bar, 2开发者_StackOverflow7px, 37px, bla
The function should be called:
myfunction(75px, 218px, foo)
and so on.
Can anybody show me an example code?
You can "split" the text on the commas:
function handleResponse(rawResponse) {
function trim(s) {
return s.replace(/^\s*/, '').replace(/\s*$/, '');
}
var attrs = rawResponse.split(',');
for (var i = 0; i < attrs.length; i += 3) {
myFunction(trim(attrs[i]), trim(attrs[i + 1]), trim(attrs[i + 2]));
}
}
edit to actually call the "trim" function I took the trouble to include :-)
精彩评论