I am trying to understand what is preventing jquery from parsing my XML reply.
My code looks like this:
$.ajax({
url: "ajax_gateway.php?request=agentdetails&agentid=6352",
dataType: "xml",
success: function(xml) {
console.log(xml);
alert($('agentname', xml).val());
//$('input[name="agent_name"]').val($('agentname', xml).val());
}
});
I can see my intended XML logged to Chrome console. I checked headers, and my AJAX reply is sent with "Content-Type: text/xml". Unfortunately my alert is empty and if I try to do:
$(xml).("agentname").val()
I get error message in chrome JS console saying "Uncaught SyntaxError: Unexpected token ( ". Am I missing something? I have several other function in my "ajax_gateway" and they are all working fine...
Edit: My XML response:
<?xml version="1.0"?> <response><employee><agentname>My Name</agentname><agentteam>My Team</agentteam><agentphoneid>6352</agentphoneid></employee></response>
While papaiatis answered my question, would anyone bother to explain why:
$(xml).("agentname").text();
Is valid?