简体   繁体   English

操作返回状态代码 204 但 AJAX 成功 function 未执行

[英]Action returns Status Code 204 but, AJAX success function doesn't execute

My controller is correctly returning new HttpStatusCodeResult(204) (checked using debugging), but the success function is not triggered.我的 controller 正确返回new HttpStatusCodeResult(204) (使用调试检查),但未触发成功 function。 I just want to reset a text field after I've submitted something.我只想在提交内容后重置文本字段。

Ajax: Ajax:

$(document).ready(function () {
        $("#offersubmit").click(function (e) {
            $.validator.unobtrusive.parse($('offerForm'));
            if ($(this).valid()) {
                var valdata = $("#offerForm").serialize();
                $.ajax({
                    url: "/Product/MakeOffer",
                    type: "POST",
                    dataType: 'json',
                    contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                    data: valdata,
                    success: $(document).ready(function () {
                        alert("AAA");
                        $('#offerText').val('');
                    })
                })
            }
        });
    });

Also tried with alert() and it didn't show anything.还尝试了alert()但它没有显示任何内容。 Any help would be appreciated任何帮助,将不胜感激

You need to remove the $(document).ready(.. code您需要删除 $(document).ready(.. 代码

success: $(document).ready(function () {
    alert("AAA");
    $('#offerText').val('');
})

should be应该

success: function(data) {
    alert("AAA");
    $('#offerText').val('');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM