我试图使用远程API,但在尝试从XMLHttpRequest访问响应之前,我一直做得很好。我可以console.log它,它看起来像这样:
angular.js:14525 Error: [$compile:tpload] Failed to load template: templates/delete-condition-modal.html (HTTP status: 404 Not Found)
我无法访问对象思想中的任何值。当我尝试解析对象的Object {
"bubbles": false,
"cancelable": false,
"currentTarget": XMLHttpRequest {
"DONE": 4,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"OPENED": 1,
"UNSENT": 0,
"_aborted": false,
"_cachedResponse": undefined,
"_hasError": false,
"_headers": Object {},
"_incrementalEvents": false,
"_lowerCaseResponseHeaders": Object {
"connection": "Keep-Alive",
"content-length": "177",
"content-type": "text/html; charset=UTF-8",
"date": "Wed, 28 Nov 2018 23:29:58 GMT",
"keep-alive": "timeout=5, max=100",
"server": "Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.2.7 mod_perl/2.0.8-dev Perl/v5.16.3",
"x-powered-by": "PHP/7.2.7",
},
"_method": "GET",
"_requestId": null,
"_response": "REDACTED...BUT ITS A JSON ENCODED STRING HERE",
"_responseType": "",
"_sent": true,
"_subscriptions": Array [],
"_timedOut": false,
"_trackingName": "unknown",
"_url": "REDACTED",
"readyState": 4,
"responseHeaders": Object {
"Connection": "Keep-Alive",
"Content-Length": "177",
"Content-Type": "text/html; charset=UTF-8",
"Date": "Wed, 28 Nov 2018 23:29:58 GMT",
"Keep-Alive": "timeout=5, max=100",
"Server": "Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.2.7 mod_perl/2.0.8-dev Perl/v5.16.3",
"X-Powered-By": "PHP/7.2.7",
},
"responseURL": "REDACTED",
"status": 200,
"timeout": 0,
"upload": XMLHttpRequestEventTarget {
Symbol(listeners): Object {},
},
"withCredentials": true,
Symbol(listeners): Object {
"load": Object {
"kind": 3,
"listener": [Function anonymous],
"next": null,
},
},
},
"eventPhase": 2,
"isTrusted": false,
"target": XMLHttpRequest {
"DONE": 4,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"OPENED": 1,
"UNSENT": 0,
"_aborted": false,
"_cachedResponse": undefined,
"_hasError": false,
"_headers": Object {},
"_incrementalEvents": false,
"_lowerCaseResponseHeaders": Object {
"connection": "Keep-Alive",
"content-length": "177",
"content-type": "text/html; charset=UTF-8",
"date": "Wed, 28 Nov 2018 23:29:58 GMT",
"keep-alive": "timeout=5, max=100",
"server": "Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.2.7 mod_perl/2.0.8-dev Perl/v5.16.3",
"x-powered-by": "PHP/7.2.7",
},
"_method": "GET",
"_requestId": null,
"_response": "REDACTED...BUT AGAIN, JSON ENCODED STRING",
"_responseType": "",
"_sent": true,
"_subscriptions": Array [],
"_timedOut": false,
"_trackingName": "unknown",
"_url": "REDACTED",
"readyState": 4,
"responseHeaders": Object {
"Connection": "Keep-Alive",
"Content-Length": "177",
"Content-Type": "text/html; charset=UTF-8",
"Date": "Wed, 28 Nov 2018 23:29:58 GMT",
"Keep-Alive": "timeout=5, max=100",
"Server": "Apache/2.4.33 (Unix) OpenSSL/1.0.2o PHP/7.2.7 mod_perl/2.0.8-dev Perl/v5.16.3",
"X-Powered-By": "PHP/7.2.7",
},
"responseURL": "REDACTED",
"status": 200,
"timeout": 0,
"upload": XMLHttpRequestEventTarget {
Symbol(listeners): Object {},
},
"withCredentials": true,
Symbol(listeners): Object {
"load": Object {
"kind": 3,
"listener": [Function anonymous],
"next": null,
},
},
},
"timeStamp": 1543447798607,
"type": "load",
Symbol(stop_immediate_propagation_flag): false,
Symbol(canceled_flag): false,
Symbol(original_event): Object {
"type": "load",
},
}
成员时,出现JSON错误(无法解析未定义)。但是,我可以看到该成员存在于此。而且,我无法解析整个对象,因为它已经在JSON中。这是我的本机代码现在的样子:
_response
这是我的问题... 如何在保留胖箭头语法的同时解析此XMLHttpRequest对象的 ajax.onload = req => {
responseObject = JSON.parse(req._response);
}
成员?