xmlhttpresponse从具有编号节点的对象创建textnode

时间:2013-11-20 15:43:01

标签: javascript ajax dom xmlhttprequest

在我的项目中,我有一个像这样的xmlhttprequest对象:

response node

现在在我的脚本中我需要创建一个带有响应对象参数的textnode,如下所示

if (typeof(response.serps) === 'undefined' || response.serps === null) {
        tse3 = document.createTextNode("NO DATA");
    } else {
        tse3 = document.createTextNode(response.serps.1.headline+"<br>"+response.serps.1.url);
    }

但编辑器在response.serps.1中出错(当我写1个号码时)。 如何使用数字从此节点获取数据?

提前致谢

1 个答案:

答案 0 :(得分:1)

您需要使用括号表示法来访问数字属性:

response.serps[1].headline