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
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
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.