Getting Database Values into HTML table? - AJAX/Javascript

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 4426 Views - Last Post: 05 April 2013 - 02:28 PM

#16 JJ1717  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-April 13

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 11:14 AM

I would also try with:

header ("Content-Type: text/xml");

even though this method is deprecated and it should really be "application/xml".
[/quote]

Just to elaborate, does this line of code need to be present on both pages.... xml and php? or just one of them?


When added onto php page error changes to null on line 88 on the xml page. -

var record = xmlHttpReq.responseXML.getElementsByTagName('record');



This code it utter madeness. I have 5 people working on this with me and we are all completely stumped.
Was This Post Helpful? 0
  • +
  • -

#17 JJ1717  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-April 13

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 11:26 AM

Ignore last post


Uncaught TypeError: Cannot read property 'firstChild' of undefined

has now moved to line 95

var fueltype = rec.getElementsByTagName("FUELTYPE")[0].firstChild.data;


so the id and carname are now ignored?

why would the error end up there?
Was This Post Helpful? 0
  • +
  • -

#18 JJ1717  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-April 13

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 11:38 AM

...correction

error's still ranging between 93 and 95 so Id and Carname still be classed as undefined.
Was This Post Helpful? 0
  • +
  • -

#19 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3809
  • View blog
  • Posts: 13,508
  • Joined: 12-December 12

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 11:52 AM

XML is case-sensitive, so change FUELTYPE to fueltype, etc..

You still seem to have a load of spaces between XML-tags. These should be removed as it is possible they will be converted to text-elements, or other nodes, so that firstChild will not refer to the correct element(s).

Your XML is now displaying correctly in the browser, and includes the <?xml header, so it is now available as responseXML, as it should be. You are almost there.
Was This Post Helpful? 0
  • +
  • -

#20 JJ1717  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-April 13

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 11:58 AM

Brilliant Andrew. Out of action for a few hours! Will make changes when I am back and post responses

Many thanks

Await my reply :)
Was This Post Helpful? 0
  • +
  • -

#21 JJ1717  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-April 13

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 01:46 PM

You sir,

Are an absolute LEGEND!


Working now.

One final question. if you press the load database button again once the data is present it will load all the values again. Is there a way to validate this so duplicate entries can't be entered???

not a major issue but if it can be implemented easily I would like to give it a try.
Was This Post Helpful? 0
  • +
  • -

#22 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3809
  • View blog
  • Posts: 13,508
  • Joined: 12-December 12

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 02:25 PM

View PostJJ1717, on 05 April 2013 - 08:46 PM, said:

You sir,

Are an absolute LEGEND!


Working now.

One final question. if you press the load database button again once the data is present it will load all the values again. Is there a way to validate this so duplicate entries can't be entered???

not a major issue but if it can be implemented easily I would like to give it a try.

Thank you.

If there is not already a specific ID that you can rely on, I would add an id to the first table-row (tr - or any other newly created element) created by your button's code such as "alreadyXML". In the button-code I would first check for the presence of this id; if it is not available, then this means the XML data has not already been inserted.

var already = document.getElementById("alreadyXML");
if (already) {
    // already run once, abort.
} else {
    // okay, continue.
}

Was This Post Helpful? 0
  • +
  • -

#23 JJ1717  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 05-April 13

Re: Getting Database Values into HTML table? - AJAX/Javascript

Posted 05 April 2013 - 02:28 PM

Ok awesome. I will look into it!

Thanks for the help.. I know where to come again if I need any more advice. Feel free to 'solved' this post or however people do this here :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2