weixin_33726313 2012-05-30 08:10 采纳率: 0%
浏览 41

Selecton在jQuery Ajax回复

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?

  • 写回答

1条回答 默认 最新

  • weixin_33724570 2012-05-30 08:17
    关注

    Try to use text() instead.

    alert($('agentname', xml).text());

    val() is used with form elements.

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码