Javascript 使用ajax检索后,JSON数据未从中显示到视图
我使用ajax从控制器检索Json数据。但是我试着在一个特定的div中展示结果,尝试了很多东西,但都不知道我做错了什么。我可以在控制台中看到它正在获取json数据,但它只是没有显示在特定的div中 下面是Json数据-Javascript 使用ajax检索后,JSON数据未从中显示到视图,javascript,c#,json,asp.net-ajax,Javascript,C#,Json,Asp.net Ajax,我使用ajax从控制器检索Json数据。但是我试着在一个特定的div中展示结果,尝试了很多东西,但都不知道我做错了什么。我可以在控制台中看到它正在获取json数据,但它只是没有显示在特定的div中 下面是Json数据- Object postage_result: costs: cost:{item: "Parcel Post", cost: "15.80"} delivery_time:"Delivered in 4 business days" service:"P
Object
postage_result:
costs:
cost:{item: "Parcel Post", cost: "15.80"}
delivery_time:"Delivered in 4 business days"
service:"Parcel Post"
total_cost:"15.80"
Ajax代码-
<script>
$.ajax({
url: '/ShoppingCart/GetFreight',
type: 'GET',
success: function (response) {
console.log(response);
weather = ko.mapping.fromJS(response); //populate the weather object
ko.applyBindings(weather);
$.each(response.postage_result, function (i, val) {
$("#cost").append(document.createTextNode(val.total_cost));
})
},
error: function (error) {
$(that).remove();
DisplayError(error.statusText);
}
});
</script>
$.ajax({
url:“/ShoppingCart/get货运”,
键入:“GET”,
成功:功能(响应){
控制台日志(响应);
weather=ko.mapping.fromJS(响应);//填充weather对象
ko.应用绑定(天气);
$。每个(响应.邮资\结果,函数(i,val){
$(“#成本”).append(document.createTextNode(val.total_成本));
})
},
错误:函数(错误){
$(that.remove();
显示错误(error.statusText);
}
});
查看代码-
<td>Freight =<div id="cost"> </div></td>
运费=
请建议我应该怎样做才能工作