Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

AJAX, PHP, XML guides/help.

Featured Replies

Hello all, my first time working with XML using PHP and JS to retrieve the information. My only problem is that I just can't seem to get it to be working. Whenever I try to push the information into my HTML I get javascript console errors stating that the tagname isn't defined and thus can't get the data. Anyway I'll post the code but it would be good if you know of any guides/tutorials when working with XML.

 

Oh also this is a very basic mailing client that I'm building so I can start to understand AJAX and such so please don't post complexities and such like security for usernames and such. That kind of stuff I can fix later.

 

Thank you.

 


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Inbox</title>
</head>

<body>

<div>
<b>Sender:</b><span id="sender"></span><br />
<b>Subject:</b><span id="subject"></span><br />
<b>date:</b><span id="date"></span>
</div>

<script>
if (window.XMLHttpRequest) {
//IE7+, Firefox, Chrome, Opera, Safari
xmlhttp= new XMLHttpRequest();
}
else
{
//IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","php/checkmail1.php?userID=admin",true);
xmlhttp.send();
xmlDoc=xmlhttp.response.XML;

document.getElementById("sender").innerHTML= xmlDoc.getElementsByTagName("sender")[0].childNodes[0].nodeValue;

</script>

</body>
</html>

 

Whenever this is run js console states tagname sender isn't defined. So the xmlDoc isn't returning the XML data for it to read?

 

and PHP

 

<?php
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
$dbhost = 'localhost';
$dbuser = 'blahdeblah';
$dbpass = '';
$dbname = 'test';
$dbtable = 'mail';

$q=$_GET["userID"];

$con = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$con)
{
 die('Could not connect: ' . mysql_error());
}
$dbselect = mysql_select_db($dbname,$con);
$sql="SELECT * FROM $dbtable WHERE userID='$q'";
$result = mysql_query($sql);
echo '<?xml version="1.0" encoding="ISO-8859-1"?><message>';
while($row = mysql_fetch_array($result))
{

echo "<mail>";
 echo "<userid>".$row['userID']."</userid>";
 echo "<sender>".$row['Sender']."</sender>";
 echo "<mailid>".$row['mailID']."</mailid>";
echo "<subject>".$row['Subject']."</subject>";
  echo "<message>".$row['Message']."</message>";
echo "<date>".$row['Date']."</date>";
 echo "<time>".$row['Time']."</time>";
 echo "<status>".$row['status']."</status>";
echo "</mail>";
}
echo "</message>";
mysql_close($con);
?>

  • Author

copy and paste the generated response ....

 

Heres what I get when I just simply use document.write(xmlDoc);

 

 

Sender:

Subject:

date:

undefined

 

<script>
if (window.XMLHttpRequest) {
//IE7+, Firefox, Chrome, Opera, Safari
xmlhttp= new XMLHttpRequest();
}
else
{
//IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","php/checkmail1.php?userID=admin",true);
xmlhttp.send();
xmlDoc=xmlhttp.response.XML;
document.write(xmlDoc);
</script>

 

Heres the output from when I use:

 

 

document.getElementById("sender").innerHTML= xmlDoc.getElementsByTagName("sender")[0].childNodes[0].nodeValue

 

Sender:

Subject:

date:

Edited by BITmixit

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.