我有 XML 和 JSON 格式的 REST 服务:
http://localhost:5050/rest/rest/report/check/ {id}/{checksum}.xml http://localhost:5050/rest/rest/report/check/ {id}/{checksum}.json
示例:调用http://localhost:5050/rest/rest/report/check/420/339d9146ddd3d6646a1fe93ddf4d7ab8c4a51c61.xml将返回结果:
<report>
<id>420</id>
<checksum>339d9146ddd3d6646a1fe93ddf4d7ab8c4a51c61</checksum>
<checksumValid>true</checksumValid>
<reportName>sprawozdanie 1</reportName>
<userName>John Smith</userName>
<state>robocze</state>
</report>
现在我想从 JQuery 调用那个 REST 服务(xml 或 json,我不在乎)。
我要做的是:
$.ajax({
type:"GET",
url:"http://127.0.0.1:5050/rest/rest/report/check/" + obj.id + "/" + obj.checksum + ".xml",
success:function (data, textStatus) {
alert('success...');
},
error:function (xhr, ajaxOptions, thrownError) {
alert("thrown: '" + thrownError + "', status: '"
+ xhr.status + "', status text: '"
+ xhr.statusText + "'");
}
});
最后我调用了错误函数,结果是:
抛出:'',状态:'0',状态文本:'错误'
我究竟做错了什么?