Jump to content

JavaScript ajax xml response


danielj

Recommended Posts

What I'm trying to do is use an xml DOM created in php to display on my webpage using an ajax call. I'm pretty sure this is a JavaScript problem, but it's possible there may be an issue with my php code. Part of the php code is below if needed. The reason I believe the php code is fine, is because if I go directly to the page and uncomment the saveHTML() line, it displays fine.

 

The first code below is my ajax call. I think the call fails, because what I get is the alert error message in my code (An error has occured). I'm not sure what the issue is.

 

Thanks for any suggestions.

request = $.ajax({				   url: "results.php", 				   type: "POST",				   dataType: "xml"				}).done(function (data){					$(data).find("stat").each(function(){						$("result").append($(this).find("fName").text() + "<br>");					});				}).fail(function (){					alert("An error has occured.");				});
$result=mysqli_query($con,$cmd);$doc = new DOMDocument("1.0", "utf-8");		$root = $doc->createElement('stats');		$doc->appendChild($root);		while($row=mysqli_fetch_array($result)){				// Creates the main xml element stat			$element = $doc->createElement("stat");						// Declares variables from SQL table to be used for sub-elements			$fName = $row['fName'];			$lName = $row['lName'];			$position = $row['position'];			$pYard = $row['pYard'];			// Create sub-elements			$pfName = $doc->createElement("fName", $fName);			$plName = $doc->createElement("lName", $lName);			$pPosition = $doc->createElement("position", $position);			$pPYard = $doc->createElement("pYard", $pYard);			// Add sub-elements to main element stat			$element->appendChild($pfName);			$element->appendChild($plName);			$element->appendChild($pPosition);			$element->appendChild($pPYard);						// Add main element to root			$root->appendChild($element);		}		//echo $doc->saveHTML();		echo $doc;
Edited by danielj
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...