Page 1 of 1
http.responsetext
Posted: Fri Aug 25, 2006 11:15 pm
by GeXus
Is it posible to put the results of this into specificed variables? How would I do that? As apposed to just the entire response.. but rather grab certain variables.... for instance i am returning 2 values, which I need as seperate values
Posted: Sat Aug 26, 2006 12:36 am
by anjanesh
Let say you are send these 2 values separated by a comma :
Code: Select all
results = http.responseText.split(",");
var a = results[0];
var b = results[1];
Posted: Sat Aug 26, 2006 8:14 am
by Chris Corbyn
Yes, with AJAX you're basically dealing with strings so you need to send grouped data back in some easily parseable form you can split(). anjanesh uses a comma here which I try to avoid since it may be present in yor string. Instead, try something like a non-printable character to use as a delimiter. I had tried the NULL byte ( \0 ) previously which works.... GAHHH except in Opera which doesn't seem to be aware of the concept of a byte with a value of zero

Instead, ascii delete works:
Code: Select all
var parts = http.responseText.split('\x7f');
document.write(parts[0]); //Value1
document.wrtie(parts[1]); //Value2
Posted: Sat Aug 26, 2006 8:27 am
by anjanesh
Better still...use XML - the
X of AJAX.
Code: Select all
<value num="1"><?php echo "Value 1"; ?></value>
<value num="2"><?php echo "Value 2"; ?></value>
Its just that parsing xml properly in JavaScript is really a headache.