如何在MVC5中通过jquery ajax调用更新部分视图并获取JSON数据?

问题描述 投票:0回答:1

我必须更新局部视图并获取json数据以更新下拉列表。如何在MVC5中通过jquery ajax调用更新部分视图并获取JSON数据?

jquery json ajax asp.net-mvc asp.net-ajax
1个回答
0
投票

最快的方法是让服务器端代码呈现部分视图并以字符串形式返回到ajax请求,然后获取ajax成功方法来替换html。

类似:

$.ajax({
    type: "GET",
    url: "your url of endpoint",
    data: {your data},
    success: function (response) {

        $('your div to replace').empty().append(response);
    },
    error:function(){
        //handle any errors
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.