XML Parsing Error - XmlHttpObj is null

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



XML Parsing Error - XmlHttpObj is null



Since moving to a https server and updating code, I'm having problems with cascading dropdown boxes that were previously working.



I get an XML Parsing Error: no element found, as well as an error telling me that XmlHttpObj.responseXML is null.



I have had some errors relating to updating the mysqli sections, and from what I have been able to work out I think the problem might be with the query. However, this is the same query that I have been using, and which has been working fine. So, I'm really not sure what is wrong here.



Ajax function causing error:


function StateChangeHandler()
// state ==4 indicates receiving response data from server is completed
if(XmlHttpObj.readyState == 4 && XmlHttpObj.status == 200)
populateCbo(XmlHttpObj.responseXML.documentElement);




XML page which is returning the null value:


<?php
// simple data provider for a cascading dropdown

Header("Content-type: text/xml");
include("db_setup.php");
session_start();
$db = $_SESSION['db_id'];
$con = mysqli_connect( C_DB_HOST, C_DB_NAME, C_DB_PASSWORD, $db );// Opens database

// get query string params

$parent = $_GET['parent'];
$level = $_GET['level'];

//Create query of other level records
$qry = "SELECT field1, field2 FROM table WHERE field3 = '".$parent."' and field4 = '".$level."'";

$result = mysqli_query($con, $qry);
mysqli_free_result($result);

// build xml content for JavaScript interpreter
$xml = "<mxml>";
$xml = $xml . '<parent_level name="0">';
$xml = $xml . '<child_level id="0"> </child_level>';
$xml = $xml . '</parent_level>';
while($row = mysqli_fetch_array($result))
$id = $row['field1'];

$value1= $row['field2'];
$value = str_replace("&", "&", $value1);

$xml = $xml . '<parent_level name="'.$parent.'">';
$xml = $xml . '<child_level id="'.$id.'">'.$value.'</child_level>';
$xml = $xml . '</parent_level>';


if (!$result)
printf("Error: %sn", mysqli_error($con)); //THIS IS NOT PRINTING ANY ERRORS
exit();


$xml = $xml . "</mxml>";
// send xml to client
echo( $xml );
?>





Where is $valueA set which is used in the query?
– Nigel Ren
Aug 7 at 14:56


$valueA





You may also find that your session_start() needs to be at the very start of this script (before header())
– Nigel Ren
Aug 7 at 15:19


session_start()


header()





Most likely the XML output from your PHP script is broken. Use the developer tools of your browser to check the it. I would suggest to use an XML Api (DOM or XMLWriter) to generate the XML output or at least escape the values using htmlspecialchars().
– ThW
Aug 7 at 15:49


htmlspecialchars()





$valueA was incorrectly labelled for this example, sorry about that - have corrected it above now. I tried moving session_start() to the top - didn't solve the problem, but gave me a slightly different error which led me to an answer: mysqli_free_result($result); needed moving to after the while loop, as it discards the result: php.net/manual/en/mysqli-result.free.php
– L.C
Aug 8 at 8:31










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard