开发者

ASP.NET HTTP POST and GET with plain JavaScript

开发者 https://www.devze.com 2023-03-15 08:11 出处:网络
In ASP.NET MVC, we can make an ajax post and get with jquery easily and get the response as it is below;

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

精彩评论

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

关注公众号