Jump to content

[SOLVED] xmlUrl has no properties - error


stereotyyppi

Recommended Posts

Hi,

 

I'm building a code that would fetch one row (url) from mysql database and then show it on a div as a test purpose.

 

Html (simplified):

 

<html>
<title>
<head>
    <script src="ajaxurl.js"></script>
</head>
</title>
<body onload="starter">
<div id="test"></div>
</body>

 

Ajax (ajaxurl.js):

 

function starter() {
loadUrl();
}

function loadUrl() {
	 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null)
 {
	alert ("Browser does not support HTTP Request")
	return;
 } 
 var url = "geturl.php" + "&sid=" + Math.random();

 xmlHttp.onreadystatechange = stateChanged;
 xmlHttp.open("GET", url, true);
 xmlHttp.send(null);
}


function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
	var xmlUrl = xmlHttp.responseXML;
	var url = xmlUrl.getElementsByTagName("url")[0].childNodes[0].nodeValue;
	document.getElementById("test").innerHTML = url;
}
}

 

PHP (geturl.php):

 

<?php
header('Content-Type: text/xml');

$con = mysql_connect('localhost', 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("wordpress", $con);

$sql = "SELECT link_url FROM wp_links WHERE link_id = '7'";

$result = mysql_query($sql);

echo '<?xml version="1.0" encoding="ISO-8859-1"?>
	<marker>';
while($row = mysql_fetch_array($result))
{
	echo "<url>" .  $row['link_url'] . "</url>";
}
echo "</marker>";

mysql_close($con);

?>

 

Xml - output of geturl.php:

 

<marker>
<url>
	http://10.0.0.135/wordpress/wp-content/uploads/2008/07/Suomenlahti_0_2008.mkx
</url>
</marker>

 

So what I´m getting is xmlUrl has no properties - error. I don´t know what I have done wrong.

Help would be appreciated.  :)

Link to comment
https://forums.phpfreaks.com/topic/114993-solved-xmlurl-has-no-properties-error/
Share on other sites

In ajax script there is of course these lines:

 

function GetXmlHttpObject() { 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
	objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.