我正在尝试从返回 html 和 json 的 Ajax 调用中检索 json 项目数据。我下面的 javascript 返回一条成功消息,这很有帮助;我只是不确定如何访问数据。我正在尝试newPrice
从此响应中访问:
Data Loaded: <pre>Array
(
[point] => 86
[claimId] => 3594
[type] => yeh
)
</pre>{"data":{"newPrice":88,"lockedInPrice":86},"errors":[],"success":true,"code":200}
我的代码如下。我特别想只返回 newPrice 值:
var newData = $.ajax({
type: "POST",
url: takeurl,
dataType: "html",
data: { point: point, claimId: id, type: val }
})
.success(function(data) {
alert("Data Loaded: " + data);
//newPrice = data.newPrice; -- returned undefined?
console.log(newPrice);
})
.error(function() { alert("not yet"); })
.complete(function(data) {
console.log('complete 1' );
});
// Set another completion function for the request above
newData.complete(function(data){
console.log("second complete" );
});
return false;
});
谢谢!