XMLを返すAPIを呼び出すJSを書いています。私は Mootools 1.3 (互換性あり) と Mootools-More 1.4 を使用しています。他の JS フレームワークは使用されていません。私のコードは次のようになります。
var req = new Request({url:'whatevs.com/api', method:'get'}).addEvent('success',
function(response_text, response_xml) {
alert(response_xml.getElement('response').getProperty('status'));
}).send();
実際の API 呼び出しは成功し、response_text は次のようになります。
<?xml version="1.0" ?>
<response status="success" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://whatevs.com/api/api.xsd">
<resultset total="0" start_index="0" results_limit="20" query="keyword=cats">
<items/>
</resultset>
</response>
ただし、"Uncaught TypeError: Object #<Document> has no method 'getElement'"
コードが実行され、呼び出しで終了すると、JS エラーが発生しgetElement
ます。Mootools は、私が理解していることから、getElement メソッドをすべての Document オブジェクトに提供します。これは response_xml です。ただし、これを行うと:
Object.getOwnPropertyNames(response_xml);
getElement
返されるプロパティのリストのどこにも見つかりません。それがなぜなのかについてのアイデアはありますか?