Forum Moderators: open
result = http.responseText;
var result = result.split(",");
alert(result[0]);
My other problem is that in tomcat, the request only gets as far as the first alert, readystate 1, then nothing. The firewall is turned off. If anyone has an idea what may be causing this, please shout.
function Parts()
{
var url="http://localhost:8080/Databases/parts.php";
if(window.XMLHttpRequest)
http = new XMLHttpRequest();
else if (window.ActiveXObject)
http = new ActiveXObject(Microsoft.XMLHTTP);
http.onreadystatechange = function()
{
alert(http.readyState);
if(http.readyState == 4)
{
alert(http.status);
if(http.status == 200)
{
result = http.responseText;
var data = result.split(",");
alert(result[0]);
}
else
{
alert("No can do!");
}
}
}
http.open("GET", url, true);
http.setRequestHeader("text");
http.send(null);
}
Thanks in advance,
RPJD :)
I'd be more likely to do it with delimiters - something like
<?php
$returnstring = '';
foreach($array as $val)
$returnstring .= $val . '*';
$returnstring = substr($returnstring,0,-1);
echo $returnstring;
?>
Then you could split on * in the javascript. Since you're returning some complex structure, you could separate the two arrays with one delimiter, the two dimensions of the second array with another delimiter, and finally the individual elements with a third delimiter.
var array = http.responseText;
if (array == false)
{
ans = 'invalid entry';
}
var fields = array.split("[],");
var parts = array.split(",[][]");
alert("done");
alert(fields);
also when I tried to split the arrays themselves
var fieldnames = fields.split(",,,,");
var parts = parts.split("[],[]");
RPJD
I got all the code from my php script
for($i=0; $i<10;$i++) {
$array[] = mysql_fetch_array($query);
}
?>
etc.?
If so then the server isn't processing the script for some reason. I'm not familiar with this:
http.setRequestHeader("text");
Is it possible that that line is causing the server to send the file back instead of executing the contents - what happens if you comment that out?
result = http.responseText.split("¦");
alert(result);
numrows = result[0];
alert(numrows);