5 Replies - 2803 Views - Last Post: 09 April 2007 - 11:26 AM Rate Topic: -----

#1 rpjd  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 08-March 07

http.responsetext and php variables

Posted 06 April 2007 - 03:22 AM

Can anyone help me? I am using an Ajax XMLHttpRequest to execute a php script which queries a database, from which I have two php arrays say $arrayname[] and $arrayname[][] that I want to display in a browser. Can anyone tell me if the following syntax is anywhere near correct?
[code]
var numfields = XMLResponse.getElementsByTagName('numfields');//number of fields in array($numfields)
var numrows = XMLResponse.getElementsByTagName('numrows');//number of rows in the array($numrows)
var arrayname[] = XMLResponse.getElementsByTagName('arrayname[]');array for column headings
var arrayname[][] = XMLResponse.getElementsByTagName('arrayname[][]');array for table data

for(i=0; i<numrows; i++)
{
for(j=0; j<numfields; j++)
{
arrayname[i][j] = arrayname[][].getAttribute('[i][j]');collects all data from table.
}
}
for(i=0; i<numfields; i++)
{
arrayname[i] = arrayname[].getAttribute('[i]');//collects column headings
}

thanks in advance

RPJD :)

Is This A Good Question/Topic? 0
  • +

Replies To: http.responsetext and php variables

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: http.responsetext and php variables

Posted 06 April 2007 - 06:11 AM

Java != Javascript
Was This Post Helpful? 0
  • +
  • -

#3 rpjd  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 08-March 07

Re: http.responsetext and php variables

Posted 06 April 2007 - 07:44 AM

View Posthotsnoj, on 6 Apr, 2007 - 06:11 AM, said:

Java != Javascript

I appreciate that hotsnoj.

I have set up an alert for my xmlhttprequest, just to see what is being passed back through http.responseText. In windows, as I expected, due to the fact that I have not done any parsing yet, I got all the code from my php script.
My xmlhttprequest executes in tomcat v5.0.28, but only get as far as http.readystate = 1(Loading) then stops/fails. Trying to figure out why. Any ideas welcome.
Does anyone know if there are any tutorials that explain how to extract multiple arrays from http.responseText, one of which is a multi-dimensional array[][]? I have yet to find one.

this is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="Javascript">
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)
			{
			alert(http.responseText)
			}	
		else	
			{
			// + " " + http.statusText;
			alert(http.status);
			}	
		} 
	}
http.open("GET", url, true); 
http.setRequestHeader("text/xml"); 
http.send(null); 
} 
</script>
</head>
<body>
<FORM name="ajax" method="POST" action="">
<p>
<INPUT type="BUTTON" value="Parts"  onclick="Parts();">
</p>
<p>
<input type="text" name="dyn" size="32" value="">
</p>
</FORM>
</body>
</html>



RPJD
Was This Post Helpful? 0
  • +
  • -

#4 rpjd  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 08-March 07

Re: http.responsetext and php variables

Posted 07 April 2007 - 08:18 AM

View Postrpjd, on 6 Apr, 2007 - 07:44 AM, said:

View Posthotsnoj, on 6 Apr, 2007 - 06:11 AM, said:

Java != Javascript

I appreciate that hotsnoj.

I have set up an alert for my xmlhttprequest, just to see what is being passed back through http.responseText. In windows(IE7), as I expected, due to the fact that I have not done any parsing yet, I got all the code from my php script.
My xmlhttprequest executes in tomcat v5.0.28, but only get as far as http.readystate = 1(Loading) then stops/fails. Trying to figure out why. Any ideas welcome.
Does anyone know if there are any tutorials that explain how to extract multiple arrays from http.responseText, one of which is a multi-dimensional array[][]? I have yet to find one.

this is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="Javascript">
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)
			{
			alert(http.responseText)
			}	
		else	
			{
			// + " " + http.statusText;
			alert(http.status);
			}	
		} 
	}
http.open("GET", url, true); 
http.setRequestHeader("text/xml"); 
http.send(null); 
} 
</script>
</head>
<body>
<FORM name="ajax" method="POST" action="">
<p>
<INPUT type="BUTTON" value="Parts"  onclick="Parts();">
</p>
<p>
<input type="text" name="dyn" size="32" value="">
</p>
</FORM>
</body>
</html>



RPJD

I have tried getting the data using
var data = http.responseText;
alert(data)


this alert gives me
[object]



I have also tried using
data = http.responseText;
var result = data.getElementById("result");


but I get "object doesn't support this properry or method" even though
if(data.getElementById)


returns true.

RPJD
Was This Post Helpful? 0
  • +
  • -

#5 rpjd  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 08-March 07

Re: http.responsetext and php variables

Posted 09 April 2007 - 10:05 AM

View Postrpjd, on 7 Apr, 2007 - 08:18 AM, said:

View Postrpjd, on 6 Apr, 2007 - 07:44 AM, said:

View Posthotsnoj, on 6 Apr, 2007 - 06:11 AM, said:

Java != Javascript

I appreciate that hotsnoj.

I have set up an alert for my xmlhttprequest, just to see what is being passed back through http.responseText. In windows(IE7), as I expected, due to the fact that I have not done any parsing yet, I got all the code from my php script.
My xmlhttprequest executes in tomcat v5.0.28, but only get as far as http.readystate = 1(Loading) then stops/fails. Trying to figure out why. Any ideas welcome.
Does anyone know if there are any tutorials that explain how to extract multiple arrays from http.responseText, one of which is a multi-dimensional array[][]? I have yet to find one.

this is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="Javascript">
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)
			{
			alert(http.responseText)
			}	
		else	
			{
			// + " " + http.statusText;
			alert(http.status);
			}	
		} 
	}
http.open("GET", url, true); 
http.setRequestHeader("text/xml"); 
http.send(null); 
} 
</script>
</head>
<body>
<FORM name="ajax" method="POST" action="">
<p>
<INPUT type="BUTTON" value="Parts"  onclick="Parts();">
</p>
<p>
<input type="text" name="dyn" size="32" value="">
</p>
</FORM>
</body>
</html>



RPJD

I have tried getting the data using
var data = http.responseText;
alert(data)


this alert gives me
[object]



I have also tried using
data = http.responseText;
var result = data.getElementById("result");


but I get "object doesn't support this properry or method" even though
if(data.getElementById)


returns true.

RPJD

If I have a php script with a variable
$test = "test"


and I have text field within a php webpage. This is my text field
<form name="t" method="POST" action="ViewParts.php">
<input type="text" name="test" value=""/>
<input type="button" value="Parts" onclick="Parts();"/>
</form>


I have executed the script using an xmlhttprequest. How do I assign the value of $test to the text field?
I tried using this
var result = http.responseText;
document.t.test.value = result.getElementById("test").value;


i am getting the following warning message after readystate =4 and status = 200.
Object doesn't support this property or method


Can anyone advise me on a solution?

RPJD
Was This Post Helpful? 0
  • +
  • -

#6 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: http.responsetext and php variables

Posted 09 April 2007 - 11:26 AM

You're barking up the wrong tree, or rather, posting in the wrong forum. Try the correct forrum:
http://www.dreaminco.../showforum4.htm.

Maybe someone will move this to the correct forum so you don't have to retype...ahem...moderators...ahem :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1