在Web Api Controller返回的HTML上显示JSON

时间:2015-07-21 10:36:32

标签: asp.net json asp.net-mvc-3 asp.net-web-api

我用MVC创建了Web Api项目。我希望在HTML页面中显示JSON结果。 我该怎么做? 网址:

http://localhost:58379/api/ccpayment/GetEligibility?userid=3830&type=json

我得到的数据采用以下格式

{"DailyAllowance":10000.00,"AmountUsedForTheDay":0.00,"CDF":3.0000,"UserEligibleForCC":"EligibleButBanned"}

1 个答案:

答案 0 :(得分:0)

function getYourData() {
    $.ajax({
        url: "/yourAPI_URL",
        data: JSON.stringify({ yourPostDataIfAny }),
        type: "Post",
        datatype: "json",
        contentType: "application/json; charset=utf-8"
    }).then(function (data) {
        var response = $.parseJSON(data);

        //your input field on page
        txtAllowance.value = response.DailyAllowance;
    });
}