【问题标题】:Displaying JSON on HTML returned from Web Api Controller在从 Web Api 控制器返回的 HTML 上显示 JSON
【发布时间】:2015-10-10 18:26:13
【问题描述】:

我已经使用 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"}

【问题讨论】:

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


    【解决方案1】:
    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;
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      相关资源
      最近更新 更多