在ajax上的成功无法正常工作 [英] Success on ajax not working

查看:63
本文介绍了在ajax上的成功无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的Ajax成功代码无法正常工作.

Why is it that my code on Ajax success is not functioning.

查看

$.connection.hub.start().done(function() {
    // Populate the object with values
    $(document).on("click", "#btn_submit_schedule", function () {
        bootbox.confirm({
            title: "Save these details?",
            message: html,
            buttons: {
                confirm: {
                    label: 'YES',
                    className: 'btn-success'
                },
                cancel: {
                    label: 'NO',
                    className: 'btn-danger'
                }
            },
            callback: function (result) {
                if (result === true) {
                    $.ajax({
                        type: 'POST',
                        url: '/Member/CreateTicket',
                        data: obj,
                        succes: function (controlResult) {
                            console.log(controlResult);
                            if (controlResult === true) {
                                $.notify({
                                    icon: 'glyphicon glyphicon-star',
                                    message: "Ticket has been saved"
                                }, {
                                    animate: {
                                        enter: 'animated bounceIn',
                                        exit: 'animated bounceOut'
                                    }
                                }, {
                                    type: 'success'
                                });
                                $("#create_ticket_status").html("Created ticket successfully.");
                                chat.server.getPendingRequestCount(document.getElementById("selected_id").value);
                            } else {
                                $("#create_ticket_status").html(result);
                                $.notify({
                                    icon: 'glyphicon glyphicon-star',
                                    message: "An error has occured on creating the ticket"
                                }, {
                                    animate: {
                                        enter: 'animated bounceIn',
                                        exit: 'animated bounceOut'
                                    }
                                }, {
                                    type: 'success'
                                });
                            }
                        },
                        error: function() {
                            $.notify({
                                icon: 'glyphicon glyphicon-star',
                                message: "Error has occured in creating ticket."
                            }, {
                                animate: {
                                    enter: 'animated bounceIn',
                                    exit: 'animated bounceOut'
                                }
                            }, {
                                type: 'success'
                            });
                        }
                    });
                } 
            }
        });
    });
});

控制器

[HttpPost]
public ActionResult CreateTicket(CreateTicket ticket)
{
    if (ModelState.IsValid)
    {
        var tm = new TicketManager();
        var controlResult = tm.CreateTicket(ticket);

        return controlResult ? Json(true) : Json("An error occured on creating the ticket.");
    }
    return Json("Fill-in the required fields.");
}

我实际上可以在检查器的响应"选项卡中看到结果为true,并且可以将其保存在数据库中.为什么成功功能不起作用,这超出了我的范围. 如果我有意创建一个错误,我可以看到我的错误功能起作用.你能指出我做错了什么吗?

I can actually see the result as true in the reponse tab of the inspector and I can save in my database. Why the success function is not working, is beyond me. If I intentionally create an error, I can see the my error function works. Can you point out what I am doing wrong?

推荐答案

有错字

成功:函数(controlResult){

succes: function (controlResult) {

您可以更正它,并尝试将成功设为double s

can you correct it and try as success with double s

这篇关于在ajax上的成功无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆