weixin_33674437 2014-05-19 20:44 采纳率: 0%
浏览 52

解析AJAX响应

I would like to just say thank you for anyone that helps. But I am not able to parse my AJAX response properly:

My AJAX Request:

$('#sumbit_LoggingGet').on 'click', ->
username = $('#login_username').val()
password = $('#login_password').val()
mac_id = $('#login_LoggingGetmac').val()
id = $('#login_LoggingGetid').val()

$.ajax
  type: "GET"
  url: start_url + mac_id + "/log-config/" + id
  dataType: "json"
  crossDomain: true
  cache: false
  beforeSend: beforeSend(username, password)

  success: (data) ->
    console.dir data
    successMessage("""<h1>Logging Get Results</h1>""")
    clearColor(areaText = '#header_username')
    clearColor(areaText = '#header_password')
    clearColor(areaText = '#header_LoggingGetmac')
    clearColor(areaText = '#header_LoggingGetid')

    for key,value of data
      $('#data-results').append """<br>
      <h3><span style="color: #0000CD;"> #{key}</span></h3>
      <br><h4> #{value} #{value.id}</h4><br>"""

Results:

id

logger1 undefined

points

[object Object] undefined

reports

[object Object] undefined

capacity

16070400000 undefined

True Results:

{
"id": "logger1",
"points": [
    {
        "id": "00000000/pulse_1",
        "interval": 300000,
        "enabled": true
    }
],
"reports": [
    {
        "collector": "collector1@talkrnd.enernoc.net",
        "interval": 300000,
        "enabled": true
    }
],
"capacity": 16070400000
}
  • 写回答

3条回答 默认 最新

  • weixin_33691700 2014-05-19 20:52
    关注

    It is working correctly. Your undefineds are accurate, since none of your values are objects with an id property. All of your values are either arrays or strings.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器