当前位置 博文首页 > weixin_39538536的博客:asp.net mvc jquery ajax post,javascri

    weixin_39538536的博客:asp.net mvc jquery ajax post,javascri

    作者:[db:作者] 时间:2021-09-02 10:24

    In response to Matt, another way to submit the form data is, instead of the JSON, you could call $('#form').serialize() in the 'data' field of the jQuery.ajax function. This would eliminate the need for a plugin.

    Also, I'm not an expert on this subject, still trying to learn it myself, but is it necessary to have both a POST and GET request when you could insert the response from ASP.NET MVC into the page instead? This would result in one request. There might be a valid reason for that approach though. I guess mine would look like this:

    // The Controller Action should return a PartialView as response,

    // so just a user control that contains the comments.

    function PostComment(targetUserID, commenterUserID, comment)

    jQuery.ajax({

    type: 'POST',

    data: $('#commentForm').serialize(),

    url: 'Comments/Add',

    success: function(result){

    $('#comments').html(result);

    }

    }

    });

    cs