2014-04-29 40 views
0

顯示的數據,如果我運行此代碼菲德勒顯示JSON數據回來正常,但我不能讓這些數據在我的HTML頁面顯示在所有。我正在嘗試一些簡單的事情來展示JS警報返回的JSON數據。我可以在我編寫的其他程序中使用這種方法,但無法弄清楚爲什麼它不在這裏工作,因爲Fidler每次都會顯示正確的JSON格式的數據。我相信我下面的代碼只運行第一行然後鎖定。請指教,謝謝。的getJSON不使用Web API

 $.getJSON('http://199...:8010/api/values/', { id: '000101' }, function (data) { 
      $.each(data, function (index, RevenueCenters) { 
       alert(RevenueCenters.Total); 
      }); 
     }); 

enter image description here

這是從在菲德勒的原始部分:

{ 「空白」:NULL, 「STATEMENTDATE」: 「20140228」, 「MEMBERID」: 「000102」,「Chargedate 「:」 20140218" , 「TrackingNumber」: 「PAYMNT」, 「描述」: 「PAYMENT CK:007591(1)」, 「SalesAmount兩個」: 「 - 874.00」, 「ServiceCharge」: 「 - 874.00」, 「PST」: 「0.00」, 「全」: 「 - 874.00」, 「ChitCode」: 「PAYMNT」, 「簽名者」:空, 「BLANK2」:空},{ 「空白」:空, 「STATEMENTDATE」: 「20140228」,」 MEMBERID 「:」 000102" , 「Chargedate」: 「20140222」, 「TrackingNumber」: 「192738」, 「說明」: 「小吃店」, 「SalesAmount兩個」: 「2.00」, 「ServiceCharge」: 「2.00」,「PST 「:」 0 .21「,」Total「:」2.57「,」ChitCode「:」192738「,」Signer「:null,」Blank2「:null}

這就是瀏覽器中的樣子,手動API調用:

{

"Blank": null, 
"StatementDate": "20140228", 
"MemberID": "000102", 
"Chargedate": "20140218", 
"TrackingNumber": "PAYMNT", 
"Description": "PAYMENT CK:007591(1)", 
"SalesAmount": "-874.00", 
"ServiceCharge": "-874.00", 
"PST": "0.00", 
"Total": "-874.00", 
"ChitCode": "PAYMNT", 
"Signer": null, 
"Blank2": null 

},{

"Blank": null, 
"StatementDate": "20140228", 
"MemberID": "000102", 
"Chargedate": "20140222", 
"TrackingNumber": "192738", 
"Description": "SNACK BAR ", 
"SalesAmount": "2.00", 
"ServiceCharge": "2.00", 
"PST": "0.21", 
"Total": "2.57", 
"ChitCode": "192738", 
"Signer": null, 
"Blank2": null 

},

+0

也許問題出在你的處理器或循環的代碼。你可以發佈一個JSON樣子的樣本嗎? – Jacob

+0

你有沒有解析過的JSON?我不清楚如何解讀該圖像。你找回一個JSON數組嗎? – Jacob

+0

Firefox Firebug顯示我的回覆爲空,但Fidler顯示JSON回來。 –

回答

0

試試這個

$.ajax({ 
    type : "POST", 
    url : "your url here!!", 
    dataType : "json", 
    success : function(obj) { 
     // your code here 
    }, 

    error : function() { 
    // exception here 
    } 
}); 
+0

和參考網址http://api.jquery.com/jquery.getjson/ –

+0

我試過,但它是相同的效果,JSON回來在菲德勒,但我不知道如何來顯示它在我的HTML頁面。 –

+0

我想知道你的控制檯日誌。例如:console.log(JSONDATA); –