我正在对这样的API进行AJAX调用,
<script type = "text/javascript">
$.ajax({
url: "http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=APLE",
dataType: 'jsonp',
success: function(results){
var status = results.response.Status;
var company = results.response.Symbol;
$('#results').append(status + '. Company is: ' + company);
}
});
</script>
收到回复后,我正在尝试解析其中的某些数据,并将其附加到<div>
中的<body>
。
<body>
<div id="results"></div>
</body>
我有我正在处理的代码 - http://jsbin.com/hofosaveho/edit?html,output
我在这里做错了什么?
答案 0 :(得分:4)
您返回的对象没有响应属性
尝试:
success: function(results){
alert(results);
var status = results.Status;
var company = results.Name;
$('#results').append(status + ' OK. Company is: ' + company);
}
答案 1 :(得分:2)
这是您的样本回复
[object Object] {
Change: 0.0999999999999979,
ChangePercent: 0.507356671740223,
ChangePercentYTD: -0.801201802704057,
ChangeYTD: 19.97,
High: 19.81,
LastPrice: 19.81,
Low: 19.57,
MarketCap: 3460113650,
MSDate: 42460.6659722222,
Name: "",
Open: 19.76,
Status: "SUCCESS",
Symbol: "APLE",
Timestamp: "Thu Mar 31 15:59:00 UTC-04:00 2016",
Volume: 49025
}
或许更新您的服务器返回?