getJSON不使用Web API显示数据

时间:2014-04-29 01:45:34

标签: jquery asp.net-web-api

如果我运行此代码,Fidler会显示正确返回的JSON数据,但我无法将这些数据显示在我的HTML页面中。我尝试了一些简单的事情,首先展示了使用JS警报返回的JSON数据。我可以在我编写的其他程序中使用这种方法,但无法弄清楚为什么它不能在这里工作,因为Fidler每次都会以正确的JSON格式显示数据。我相信下面的代码只运行第一行,然后锁定。请指教,谢谢。

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

enter image description here

这来自Fidler的Raw部分:

{"空白":空," STATEMENTDATE":" 20140228"" MEMBERID":" 000102" " Chargedate":" 20140218"" TrackingNumber":" PAYMNT""说明":"付款CK:007591(1)"," SalesAmount":" -874.00"," ServiceCharge":" -874.00&#34 ;," PST":" 0.00""总计":" -874.00"" ChitCode&#34 ;: " PAYMNT""签名者":空," BLANK2":空},{"空白":空," STATEMENTDATE&# 34;:" 20140228"" MEMBERID":" 000102"" Chargedate":" 20140222"&# 34; TrackingNumber":" 192738","描述":" SNACK BAR"," SalesAmount":" 2.00 "" ServiceCharge":" 2.00"" PST":" 0.21""总计&#34 ;:" 2.57"" ChitCode":" 192738""签名者":空," BLANK2&#34 ;:空}

如果我只是手动运行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

},

1 个答案:

答案 0 :(得分:0)

试试这个

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

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