Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-08-2009, 06:26 PM   PM User | #1
itgetsharder
New to the CF scene

 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
itgetsharder is an unknown quantity at this point
ajax mysql php

Hi, im pretty new to this. basically, i have two database tables in mysql, one called items(id of the book, cookieid, quantity) and the other books(id, name, desc, price). my php returns xml(name, price, quantity and total amount). my code returns the name and price but i can't get it to return the quantity or total.

can anyone see any errors in my code? i think the problem is with the quantity which is the variable newCell2. I keep getting the error "object expected" with that part in IE.


if (request.readyState==4) {
if(request.status==200) {

var response =request.responseXML;
for(var i=0; i<=response.getElementsByTagName('store').length; i++)
{
var newRow = document.getElementById('table').insertRow(-1); // Insert the third row
var newCell1 = newRow.insertCell(0); // Insert the first cell
newCell1.innerHTML = response.getElementsByTagName('book')[i].childNodes[1].childNodes[0].nodeValue; // First cell's innerHTML
var newCell3 = newRow.insertCell(2); // Insert the second cell
newCell3.innerHTML = response.getElementsByTagName('book')[i].childNodes[3].childNodes[0].nodeValue;
var newCell2 = newRow.insertCell(1); // Insert the second cell
newCell2.innerHTML = response.getElementsByTagName('book')[i].childNodes[4].childNodes[0].nodeValue; // Second cell's innerHTML
var newCell4 = newRow.insertCell(3); // Insert the second cell
newCell4.innerHTML = response.getElementsByTagName('book')[i].childNodes[5].childNodes[0].nodeValue;
}


thanks in advance.
itgetsharder is offline   Reply With Quote
Old 05-08-2009, 07:53 PM   PM User | #2
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
Would you please post a valid XML example (that this script expects)? Please use the CODE tags when posting.

Also, consider using JSON for this, as its lightweight and much easier to handle than XML.
bdl is offline   Reply With Quote
Old 05-08-2009, 07:59 PM   PM User | #3
itgetsharder
New to the CF scene

 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
itgetsharder is an unknown quantity at this point
thanks for the reply. the xml is embedded in the php, but i know that the php and sql db are correct.

Code:
echo '<?xml version="1.0" encoding="ISO-8859-1"?><store>';
	while($row = mysql_fetch_array($result1))
  	{

	echo "<book>";
	echo "<id>".$row['id']."</id>";
	echo "<name>".$row['name']."</name>";
	echo "<description>".$row['description']."</description>";
	echo "<quantity>".$count."</quantity>";
	echo "<price>".$row['price']."</price>";
	echo "<sum>".$count*$row['price']."</sum>";
	echo "</book>";

	}
    }

  }

}
echo "</store>";
any ideas?
itgetsharder is offline   Reply With Quote
Old 05-09-2009, 01:22 AM   PM User | #4
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
No, I was looking for the actual XML. Pull up that PHP script in your browser and post the XML with content. You need to start troubleshooting with the actual data the Ajax request sees.
bdl is offline   Reply With Quote
Old 05-09-2009, 08:38 PM   PM User | #5
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
in general, it's more reliable to use getElementsByTagName('XXX') than childNodes, which can change between files and browsers.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Old 05-10-2009, 03:59 PM   PM User | #6
itgetsharder
New to the CF scene

 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
itgetsharder is an unknown quantity at this point
thank you for your reply.
i can get the name decription and price to show but the quantity and sum won't show. ill keep trying.
itgetsharder is offline   Reply With Quote
Old 05-11-2009, 03:42 AM   PM User | #7
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
You probably have a whitespace node issue.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:15 AM.


Advertisement
Log in to turn off these ads.