xmlhttprequests in firefox

getting xmlhttprequests to work in firefox

Page 1 of 1

7 Replies - 1071 Views - Last Post: 27 April 2007 - 03:17 PM

#1 rpjd  Icon User is offline

  • D.I.C Head

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

xmlhttprequests in firefox

Posted 26 April 2007 - 02:01 AM

I have been able to get xmlhttprequests to work in IE but not in firefox. after reading up on the problem, I read about firefox extensions with firebug. Do ajax xmlhttprequests require firebug in order to execute in firefox? If so, how is firebug installed? I downloaded the installer for firebug, but XP does not recognise the .xpi installer extension.
Is This A Good Question/Topic? 0
  • +

Replies To: xmlhttprequests in firefox

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: xmlhttprequests in firefox

Posted 26 April 2007 - 07:23 AM

You probably have something wrong in the actual code. You'll need to share that with us before we can help you further.

And no, firebug is not needed as it's just a debugging tool.
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: xmlhttprequests in firefox

Posted 26 April 2007 - 02:19 PM

View Posthotsnoj, on 26 Apr, 2007 - 07:23 AM, said:

You probably have something wrong in the actual code. You'll need to share that with us before we can help you further.

And no, firebug is not needed as it's just a debugging tool.


Here is the code
viewParts.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<? include("http://localhost/Project/parts.php") ?>
<HTML>
 <HEAD>
  <TITLE> ALLIED AUTO PARTS </TITLE>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <script language="Javascript">
function Parts()
	{ 
	var url="http://localhost/Project/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)
				{
				response = http.responseText;
				alert(response);
				if (document.getElementById)
					{
					alert("ok");
												  document.getElementById("numrows").innerHTML=http.responseText;
					alert(numrows);	
					}
				else	
					{
				alert("Failed");
					} 
				}
			} 
		}
		http.open("GET", url, true); 
		http.setRequestHeader("text"); 
		http.send(null); 
	} 
</script>
	 </HEAD>
	<BODY>
	<form action="viewParts.php">
	<input type="button" name="getParts" id="getParts" value="getParts" onclick="Parts();" />
	</form>
	<p>
	<script type="text/javascript" language="javascript">
	function displayParts()
	{
	var fieldname = new Array();
	var parts = new Array();
	var numfields;
	var numrows;
	document.write('<tr>');
	for (j=0; j < numfields; j++)
		{
		document.write('<td><div id="fieldname[j]"></td>');
		}
	document.write('<\/tr>');
	for (i=0; i < numrows; i++)
		{
		document.write('<tr>');
		for (j=0; j < numfields; j++)
			{
			document.write('<td><div id="parts[i][j]" /></td>');
			}
			document.write('</tr>');
		}
	}
	</script>
	<p>
	<TABLE align="center">
<TR>
	<TD align="center" colspan="6"><H3>Choose from the following funtions</H3></TD>
</TR>
<TR>
	<TD><a href="ViewParts.php">View Parts</a></TD>
	<TD><a href="Purchases.php">Purchases</a></TD>
	<TD><a href="Sales.php">Sales</a></TD>
	<TD><a href="UpdateParts.php">Add parts</a></TD>
	<TD><a href="UpdateCustomer.php">Update Customer</a></TD>
	<TD><a href="UpdateSupplier.php">Update Supplier</a></TD>
</TR>
</TABLE>
</BODY>
</HTML>


I am getting as far as
alert("ok");


then a message "document.getElementById(...) is null or not an object.

If I replace
if (document.getElementById)


with
if (response.getElementById)


I get "failed" alert.
Was This Post Helpful? 0
  • +
  • -

#4 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: xmlhttprequests in firefox

Posted 26 April 2007 - 02:21 PM

Because there is no such method in the response object. http.responseText is just plain old text, a string in other words. Just as if you did someVariable = "sometext";.
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: xmlhttprequests in firefox

Posted 26 April 2007 - 03:05 PM

View Posthotsnoj, on 26 Apr, 2007 - 02:21 PM, said:

Because there is no such method in the response object. http.responseText is just plain old text, a string in other words. Just as if you did someVariable = "sometext";.

I see what you are saying, the responseText holds text strings in the form of variable/array names and their values. Every website I have visited explains how to extract the data, depending on the format its held in, be it plain text, xml etc. with getElementbyId or Name/Tag? Is there another way of extracting the info from responseText?
Was This Post Helpful? 0
  • +
  • -

#6 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: xmlhttprequests in firefox

Posted 27 April 2007 - 09:42 AM

Well they're wrong because getElementById doesn't work with the XML objects currently and it sure as hell doesn't work with strings.

The only way to extract data from a string is to have a syntax and parse it.
Was This Post Helpful? 0
  • +
  • -

#7 rpjd  Icon User is offline

  • D.I.C Head

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

Re: xmlhttprequests in firefox

Posted 27 April 2007 - 01:10 PM

View Posthotsnoj, on 27 Apr, 2007 - 09:42 AM, said:

Well they're wrong because getElementById doesn't work with the XML objects currently and it sure as hell doesn't work with strings.

The only way to extract data from a string is to have a syntax and parse it.

Fair enough. Back to my original Q, what is preventing this from running in firefox? The request is making a connection to the database, as I am getting readystate 1 via an alert. I am wondering if it has anything to do with the fact its trying to execute a php script and not javascript. But then it it were the problem, it wouldn't connect at all. Any ideas anyone?

rpjd
Was This Post Helpful? 0
  • +
  • -

#8 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 64
  • View blog
  • Posts: 3,505
  • Joined: 31-March 03

Re: xmlhttprequests in firefox

Posted 27 April 2007 - 03:17 PM

That's not your original question.

And furthermore it's likely failing at the document.getElementById because you have no gorram element with the id of "numrows".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1