成功和错误功能Ajax调用不点火 [英] Success and Error functions not firing in Ajax call

查看:127
本文介绍了成功和错误功能Ajax调用不点火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个Ajax调用我使用以确定要显示给用户(我知道这是一个有缺陷的方法,只需补防的演示时间紧缩)的菜单选项。页面加载时,我可以通过Visual Studio中的控制器的方法步骤,所以我知道它击中控制器和发回正确的信息。

Below is an Ajax call I'm using to determine which menu options to show to users (I know it's a flawed method, just up against a time crunch for a demo). When the page loads, I can step through the controller method in Visual Studio so I know it's hitting the controller and sending back the right information.

看着Chrome的网络控制台,我也可以看到浏览器接收到正确的反应。然而,无论是的console.log 警报的射击。在成功没有什么错误方法,要么执行。有谁看到什么错?

Looking at Chrome's Network console I can also see that the browser received the right response. However, neither the console.log or the alert are firing. Nothing in the success or error methods is executed either. Does anyone see what's going wrong?

查看

    $(document).ready(function ($) {
        //Determine which links to show in navbar
        window.onload = function () {
            $.ajax({
                type: 'GET',
                url: '@Url.Action("CheckSecurity","Home")',
                dataType: 'json',
                succcess: function (data) {
                    console.log(data);
                    alert(data);
                    if (data == "admin") { $('#adminLink').show(); }
                    else if (data == "IT") { $('#ITLink').show(); }
                    else if (data == "viewer") { $('#viewerLink').show(); }
                    else if (data == "modifier") { $('#modifierLink').show(); }
                },
                error: function (data) {
                    alert("error");
                }
            });
        };

控制器

    [HttpGet]
    public JsonResult CheckSecurity()
    {
        if (Security.IsAdmin(User)) return Json("admin", JsonRequestBehavior.AllowGet);
        if (Security.IsItSupport(User)) return Json("IT", JsonRequestBehavior.AllowGet);
        if (Security.IsViewer(User)) return Json("viewer", JsonRequestBehavior.AllowGet);
        if (Security.IsModifier(User)) return Json("modifier", JsonRequestBehavior.AllowGet);

        return Json("NA", JsonRequestBehavior.AllowGet);
    }

下面是网络的一对夫妇的屏幕截图,并在Chrome常规控制台。懒得从后我通过控制器的方法加强和程序返回的值返回给浏览器。

Here are a couple screen shots of the Network and regular console in Chrome. Bother are from after I've stepped through the controller method and the program has returned a value back to the browser.

网络控制台

标准控制台

推荐答案

有一个额外的 C

成功的情况下:

所以响应是一个200的要求,而是因为你有中定义的成功没有映射,它只是从未登录

So the response is a 200 request , but because you have no mapping for success defined, it is just never logged

这篇关于成功和错误功能Ajax调用不点火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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