2015-07-21 96 views
0

我已经创建了带有MVC的Web Api项目。我想要在HTML页面中显示JSON结果。 我应该怎么做? 网址:从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"} 

回答

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; 
    }); 
}