stereotyyppi Posted July 16, 2008 Share Posted July 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
stereotyyppi Posted July 16, 2008 Author Share Posted July 16, 2008 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 } Quote Link to comment Share on other sites More sharing options...
stereotyyppi Posted July 21, 2008 Author Share Posted July 21, 2008 I solved it by myself. I had forgotten to put ? - character on session id. from var url = "geturl.php" + "&sid=" + Math.random(); to var url = "geturl.php" + "?sid=" + Math.random(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.