Object
response: "[{"id":"28","class_id":"1463","voluntary1":"1000","voluntary2":"1000","voluntary3":"1000","assigned_risk":"1500","state":"Alabama"}]"
我试图通过调用以下内容访问上方的voluntary3
数据并将其追加到我的输入#input_52_22
上:
document.getElementById('#input_52_22').value= +Object.response.voluntary3;
但是它响应以下控制台错误。
VM26293:1 Uncaught TypeError: Cannot read property 'voluntary3' of undefined
at <anonymous>:1:65
下面是响应的屏幕截图;我只是想尝试自愿并附加作为我的输入ID值:
我正在努力从外部文件(原始的ajax成功调用之外执行此操作,可能是为什么?)
答案 0 :(得分:3)
您记录的对象具有response
属性,因此它是obj.response
而不是Object.response
,并且它是一个字符串,因此必须对其进行解析:
JSON.parse(/*obj*/.response).voluntary3