getting/parsing xml from ajax
I'm building an application with a c#.net server and a good bit of jquery on the front end.
I'm having trouble getting/parsing data from c#.
In the C#, I am doing a db call to pull the information for all users, and putting it into xml format:
-
string xml = "<?xml version='1.0' encoding='utf-8' ?>";
xml += "<Users>";
while (res.Read())
{
xml += "<User>";
xml += "<Userid>" + res.GetValue(0) + "</Userid>";
xml += "<Username>" + res.GetValue(1) + "</Username>";
xml += "<Roles>" + res.GetValue(3) + "</Roles>";
xml += "</User>";
}
xml += "</Users>";
res.Close();
return xml;
On the front end, here is the jQuery:
-
function getAllUsers()
{
$.ajax({
type: "POST",
url: "../AjaxServices.asmx/GetSIMUsers",
dataType: "xml",
success: AjaxSucceeded,
});
}
function AjaxSucceeded(xml)
{
alert("in AjaxSucceeded" + xml.toString());
$(xml).find("User").each(function()
{
alert("in each");
alert($(this).find("Username").text());
});
}
When I run the application, I'm getting the 'in AjaxSucceeded [object XMLDocument]' alert, but I cannot get inside of the 'each' loop.
Any help would be greatly appreciated.
I can post more code if that would be helpful.
Thanks in advance,
Jason