开发者

ASP.NET HTTP POST and GET with plain JavaScript

In ASP.NET MVC, we can make an ajax post and get with jquery easily and get the response as it is below;

NOTE : Code is quoted from another question on stackoverflow.com

function UpdateComments(){
    resultHTML = jQuery.ajax({
        type: 'GET',
        url: 'Comments/List/UserID'
    }).responseText;

    $('#co开发者_如何学编程mments').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();                    
            }
        }
    });

What is the way of doing the above functions without any additional library and just with plain JavaScript


with XMLHttpRequest , explore this , plain javascript

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜