在ASP.NET MVC中,我们可以轻松地发布一个ajax帖子并获得响应,如下所示;
注意:代码引用自关于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,执行上述函数的方法是什么?
发布于 2011-06-24 11:27:34
使用XMLHttpRequest,探索一下简单的javascript
https://stackoverflow.com/questions/6467068
复制相似问题