我正在用 JavaScript 创建一个 Pebble 应用程序,用于显示我所在城市的公交时间。我目前在向相关 API 发送 AJAX 请求时遇到了困难。我的代码如下:
var UI = require('ui');
var ajax = require('ajax');
var card = new UI.Card({
title:'Bus data',
subtitle:'Fetching...' });
ajax({
url: "http://siri.nxtbus.act.gov.au:11000/APIKEY/pt/service.xml",
method: "post",
type: 'xml',
data: '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><Siri version="2.0" xmlns:ns2="http://www.ifopt.org.uk/acsb" xmlns="http://www.siri.org.uk/siri" xmlns:ns4="http://datex2.eu/schema/2_0RC1/2_0" xmlns:ns3="http://www.ifopt.org.uk/ifopt"><ServiceRequest><RequestTimestamp>2013-12-29T12:58:29</RequestTimestamp><RequestorRef>APIKEY</RequestorRef><ProductionTimetableRequest version="2.0"><RequestTimestamp>2013-12-29T12:58:29</RequestTimestamp><ValidityPeriod><StartTime>2015-02-20T13:50:04+01:00</StartTime><EndTime>2015-02-21T13:50:04+01:00</EndTime></ValidityPeriod><Lines><LineDirection><LineRef>ACT_200</LineRef><DirectionRef>A</DirectionRef></LineDirection></Lines></ProductionTimetableRequest></ServiceRequest></Siri>'
}, function(data) {
// Success!
console.log('Successfully fetched bus data!');
console.log(data); },
function(error) {
// Failure!
console.log('Failed fetching weather data: ' + error);
}
);
但是,这是我得到的 AJAX 响应:
<Siri xmlns="http://www.siri.org.uk/siri" xmlns:ns2="http://www.ifopt.org.uk/acsb" xmlns:ns3="http://www.ifopt.org.uk/ifopt" xmlns:ns4="http://datex2.eu/schema/2_0RC1/2_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://www.siri.org.uk/siri ../siri.xsd">
<ServiceDelivery>
<ResponseTimestamp>2015-02-20T16:44:41+11:00</ResponseTimestamp>
<ProducerRef>ACT</ProducerRef>
<Status>false</Status>
<ErrorCondition>
<OtherError number="103">
<ErrorText>wrong subscription request XML structure</ErrorText>
</OtherError>
</ErrorCondition>
</ServiceDelivery>
</Siri>
我不确定为什么会收到此回复,我非常感谢您在这件事上提供的帮助。
这是我正在使用的 SIRI API 的文档,如果您想看看:https://drive.google.com/file/d/0B3r1ipRAb5pKQnAxYi1ESEhOanc/view?usp=sharinghttps://drive。 google.com/file/d/0B3r1ipRAb5pKQnAxYi1ESEhOanc/view?usp=sharing