http.responsetext
Moderator: General Moderators
http.responsetext
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
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];- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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
echo "Value1\x7fValue 2";
exit();Code: Select all
var parts = http.responseText.split('\x7f');
document.write(parts[0]); //Value1
document.wrtie(parts[1]); //Value2
Better still...use XML - the X of AJAX.
Its just that parsing xml properly in JavaScript is really a headache.
Code: Select all
<value num="1"><?php echo "Value 1"; ?></value>
<value num="2"><?php echo "Value 2"; ?></value>