Javascript 为什么我能';无法获取已解析的XHR请求的值?
我遇到了一个问题。我必须修复以下代码:Javascript 为什么我能';无法获取已解析的XHR请求的值?,javascript,json,web,xml-parsing,xmlhttprequest,Javascript,Json,Web,Xml Parsing,Xmlhttprequest,我遇到了一个问题。我必须修复以下代码: let xhr=new-XMLHttpRequest() 问题在第六排。Chrome debugger说,这里的最后一个参数(我的意思是[“delete”])不正确:“无法读取未定义的属性“delete” 你能帮我一下吗,我该如何解决这个问题?如果这是你得到的错误,那么xhrJson[“数据”][“非时间”]将生成未定义的。您可以通过更改代码以从实际结构(没有数据->nonces值)获取值来修复它,或者更改调用以返回您期望的结构(具有数据->nonces值
let xhr=new-XMLHttpRequest()代码>
问题在第六排。Chrome debugger说,这里的最后一个参数(我的意思是[“delete”])不正确:
“无法读取未定义的属性“delete”
你能帮我一下吗,我该如何解决这个问题?如果这是你得到的错误,那么xhrJson[“数据”][“非时间”]
将生成未定义的。您可以通过更改代码以从实际结构(没有数据
->nonces
值)获取值来修复它,或者更改调用以返回您期望的结构(具有数据
->nonces
值的结构)
1 xhr.onreadystatechange = function() {
2 if ( xhr.readyState == 4 && xhr.status == 200 ) {
3 // console.log( xhr.response );
4 xhrJson = JSON.parse( xhr.response );
5 imgId = xhrJson[ "data" ][ "id" ];
6 imgNonceDelete = xhrJson[ "data" ][ "nonces" ][ "delete" ];
7 imgDeleteButton.dataset.img_id = imgId;
8 imgDeleteButton.dataset.nonce_delete = imgNonceDelete; ...