【发布时间】:2011-06-24 11:24:54
【问题描述】:
在 ASP.NET MVC 中,我们可以通过 ajax post 和 jquery 轻松获取响应,如下所示;
注意:代码引用自另一个 stackoverflow.com上的问题
function UpdateComments(){
resultHTML = jQuery.ajax({
type: 'GET',
url: 'Comments/List/UserID'
}).responseText;
$('#comments').html(resultHTML);
}
function PostComment(targetUserID, commenterUserID, comment)
jQuery.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: $.toJSON({review: comment, id:targetUserID, commenter:commenterUserID}),
dataType: 'json',
url: 'Comments/Add',
success: function(result){
// Only update comments if the post was successful:
resultJson = $.evalJSON(result);
if(resultJson['success'] == true){
UpdateComments();
}
}
});
在没有任何额外库且只使用纯 JavaScript 的情况下执行上述功能的方法是什么
【问题讨论】:
标签: javascript jquery asp.net asp.net-mvc json