302在ajax request.didnt中找到了要执行的post操作。如何解决此问题

时间:2019-01-22 06:34:39

标签: json ajax asp.net-mvc

我的视图中有一个选择框。一个ajax请求通过其更改传递,但发现302错误。下面是我的代码。它没有对控制器动作起作用。在网络标头中找到了状态码302为什么会出现此错误以及如何解决此问题。这是代码:

$(document).on('change', '.memberType', function () {       
    var memberTypeID = $(".memberType").val();         
    if (memberTypeID != null) {
        alert(memberTypeID)
        $.ajax({
            type: "POST",
            url: "@Url.Action("GetDetailsMember", "Approvemembership")",
            data: JSON.stringify({ memberTypeIDJson: memberTypeID }),
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                data = JSON.parse(data)

                if (data.IsStaff ){
                    $('.staffDetail').show();
                    $('.studentDetail').hide();
                }
                else if (data.IsStudent) {

                    $('.studentDetail').show();
                    $('.staffDetail').hide();
                }
                else {
                    $('.staffDetail').hide();
                    $('.studentDetail').hide();
                }
            }
        });
    }
})

   public string GetDetailsMember(string memberTypeIDJson)
   {         
       SchooberrySchoolEntities db=new SchooberrySchoolEntities();
       var memberType = db.LibraryMemberTypes.Where(p => p.MemberTypeId == memberTypeIDJson).Select(p =>new{IsStudent=p.IsStudent,IsStaff=p.IsStaff}).FirstOrDefault();

       if (memberType != null)
       {
           return JsonConvert.SerializeObject(memberType);
       }
       else
       {
           return "false";
       }          
    }

1 个答案:

答案 0 :(得分:0)

将您的网址url:“ @ Url.Action(” GetDetailsMember“,” Approvemembership“)”更改为网址:“ / Approvemembership / GetDetailsMember”。

请检查此答案AJAX POST to MVC Controller showing 302 error