【发布时间】:2015-12-27 09:06:00
【问题描述】:
当我尝试访问以下网址时:
http://dhclinicappv2stg.item-soft.co.il/LinkCareAppService.svc/json/GetFinalReportToAccount?AccountId=123
我收到 JSON 服务响应。我正在尝试通过 Jquery 阅读此响应,如下所示:
(function()
{
var serviceAPI = "http://dhclinicappv2stg.item-soft.co.il/LinkCareAppService.svc/json/GetFinalReportToAccount?AccountId=?";
$.getJSON( serviceAPI,
{
AccountId: "123"
})
.done(function( data )
{
alert(data);
});
})();
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.getJSON attempt</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div id="data"></div> <!-- in the future, I will add the data to this div -->
<script>
</script>
</body>
</html>
但我得到一个空白页,没有任何警报。控制台日志读取标题中的错误。
我做错了什么?
【问题讨论】:
-
您提供的网址返回 xml 而不是 json。
-
@Sirko 那我怎么参考呢?
-
@T.J.Crowder 这些是参数。 nosession 是一个叫做“Message”的参数,true 是一个叫做“Error”的参数。在控制台中,我可以看到它们配对为 JSON
-
@A.Abramov:我只是查看了发回内容的来源。 Sirko 说得对,它是 XML,而不是 JSON。
-
@A.Abramov,您的服务 url 对于 getJSON 方法是错误的。看看我的回答!
标签: jquery json ajax web-services