我有以下的AJAX代碼下面從data.json獲取值對JSON jQuery的返回undefined值
我使用jQuery來獲取值,但我得到不確定的,當我試圖讓一些值
「類型」: 「BIndex」, 「TYPE2」: 「級」, 「額定值1」: 「A +」, 「shortDesc」: 「這是行業平均水平。」, 「的ToolTipText」:「B Lorem存有sososms「。
我試圖將它們作爲 nestedValue.type和nestedValue.type2
我怎樣才能獲得這些價值?
這是我的代碼和JSON下面
的JavaScript
<script type="text/JavaScript">
$(document).ready(function() {
var jsonData ="data.json";
console.log("jsonData " +jsonData);
var ajaxURL = jsonData;
$.ajax({
url: ajaxURL,
dataType: "json",
//jsonp:"jsoncallback",
success: function(data, textStatus, jqXHR) {
// console.log("Data " + data);
// console.log("bankName " + data.bankName);
// console.log("type " + data.type);
console.log("data, textStatus, jqXHR " + data + textStatus + jqXHR)
jQuery.each(data, function(key,value) {
console.log("type " + key + value);
});
jQuery.each(data.data[0].stressType, function(nestedKey,nestedValue) {
console.log(" aaa " + nestedValue[i].type);
console.log(" aaa " + nestedValue[i].type2);
});
var jsonVals = "";
jsonVals += '<div class="row">';
jsonVals +="<div class='col-md-2 col-sm-2 col-xs-6'>";
jsonVals +='<div class="name" >' + data.bankName+'</div>';
jsonVals +='<div class="account">' + data.holdingCompany +'</div>';
jsonVals +='<div class="approved">' + data.streetAddress+'</div>';
jsonVals +="</div>";
$("#clientData").append(jsonVals);
//});
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('FAILED to get JSON from AJAX call' + jqXHR + textStatus + errorThrown);
}
});
});
</script>
data.json
{
"bankName": " Community of Springfield",
"holdingCompany": " Holdings LLC",
"streetAddress": "123 Main St",
"city": "Your Town Name",
"stateZip": "CA-94012",
"ceritificate": "Certificate #139",
"Rating": "Ratings ",
"cTitle": "Certificate #19",
"cData": [{
"clRating": "C",
"cName": "Cal Ad",
"cScore": "1"
},
{
"clRating": "A",
"cName": "Cal Aq",
"cScore": "1"
},
{
"clRating": "M",
"cName": "Cal Aq",
"cScore": "1"
},
{
"clRating": "E",
"cName": "Cal Ay",
"cScore": "1"
},
{
"clRating": "L",
"cScore": "1",
"cName": "Cal Ad"
},
{
"clRating": "S",
"cName": "CalAcy",
"cScore": "1"
}],
"data":[{
"stressType": [{
"type": "BIndex",
"type2": "Grade",
"rating1": "A+",
"shortDesc": "This is industry average.",
"toolTipText": "B lorem ipsum sososms."
},
{
"type": " Counterparty Score",
"type2": "Score",
"rating1": "8",
"shortDesc": "This institution exhibits strong lorem ipsum lorem ipsum lorem ipsum .",
"toolTipText": "TI is a lldslsa bank."
},
{
"type": "Regulatory y",
"type2": "Condition",
"rating1": "Adequate",
"shortDesc": "This institution's ability to absorb losses alorem eipsum loelsmy.",
"toolTipText": "Btoltip slorem ipsum."
},
{
"type": "Shadow Zone",
"type2": "Score1",
"rating1": "323.18",
"type2": "Score2",
"rating2": "32.25",
"shortDesc": " stress level .",
"toolTipText": " leading indicators."
}]
}]
}
你是什麼意思:'但我沒有找回所有的values'?如果你沒有找回想要的結果,那麼你需要檢查服務器端腳本。 – vaso123
這不是服務器這是所有cleint端,我試圖得到這些值,但我得到undefined「type」:「BIndex」, 「type2」:「Grade」, 「rating1」:「A +」, 「 shortDesc「:」這是行業平均水平「, 」toolTipText「:」B lorem ipsum sososms「。 – user244394
看看我的固定小提琴鏈接 – DannyThunder