2015-07-21 62 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; 
    }); 
} 
相關問題