Javascript ajax请求在Firefox中不起作用

时间:2014-02-11 06:56:39

标签: javascript jquery ajax firefox

我上周用JavaScript编写了一个页面,并且它在Chrome上都很开心。但我现在去测试它并不适用于Firefox?

这是js:

<script>
function submitForm(e) {

    var usersRoles = new Array;
    jQuery("#dualSelectRoles2 option").each(function () {
        usersRoles.push(jQuery(this).val());
    });

    var model = new Object();
    model.userId = jQuery('#selectUser').val();
    model.rolesList = usersRoles;

    console.log('model: ' + 'user: ' + model.user + 'roles: ' + model.roleslist);
    console.log('JSON: ' + JSON.stringify(model));

    jQuery.ajax({
        type: "POST",
        url: "/Roles/AddUser",
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify(model),
        success: function (data) { showSuccessMessage(data); },
        failure: function (errMsg) {
            alert(errMsg);
        }
    });
}

//Shows the success message
function showSuccessMessage(data) {
    alert(data);
}
</script>

这是Firefox控制台中的日志:

08:52:41.746 The connection to    ws://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/connect?transport=webSockets&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAA2KcGQWCelUiHIES%2B94f0AAAAAAACAAAAAAADZgAAwAAAABAAAABBnTGT7%2FEMM9AVApgmzcAAAAAAAASAAACgAAAAEAAAAF5t2Aoc%2FIG%2FJn5x7dKmcckoAAAAZMe4uLls0XtSeN9rgEtwvx6LzueVz3XA4hHjckdichwhRfRNiExtGxQAAADp3z2swkWO0NQJP4LBX283%2BfQMEw%3D%3D&requestUrl=http%3A%2F%2Flocalhost%3A53648%2FRoles%2FAddUser%3FselectUser%3D4c1fe0a9-528c-4517-a2bc-6126776081a1&browserName=Firefox&tid=8 was interrupted while the page was loading. browserLink:62
08:52:41.802 POST http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/abort [HTTP/1.1 200 OK 1ms]
08:52:41.737 "model: user: undefinedroles: undefined" AddUser:259
08:52:41.737 "JSON: {"userId":"a9860cac-0479-4d1c-9345-b3d18b82698d","rolesList":["98d5a947-81b7-4d19-aae2-1b1ff3ad6649","b6829999-6774-493b-8cf0-61672b88430d","e3690dcf-f239-4479-8f75-d5dde262d16b"]}" AddUser:260
08:52:41.803 GET http://localhost:53648/Roles/AddUser [HTTP/1.1 200 OK 226ms]
08:52:41.763 no element found abort:1
08:52:42.146 GET http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/browserLink [HTTP/1.1 200 OK 11ms]
08:52:42.113 TypeError: $.browser is undefined ui.spinner.js:25
08:52:42.311 GET http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/negotiate [HTTP/1.1  200 OK 1ms]
08:52:42.312 GET http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/connect [HTTP/1.1 101 Switching Protocols 3ms]
08:52:42.502 GET http://localhost:53648/__browserLink/requestData/9570e91fb15a4e83b385eb959

现在我在我的控制器动作方法中设置了一个断点,其中帖子应该去,它不会触发?

这是控制器:

    //Post/ Roles/AddUser
    [HttpPost]
    public ActionResult AddUser(submitUserRolesViewModel model)
    {
        try
        {
            if (model != null)
            {

                IdentityManager idMan = new IdentityManager();
                idMan.ClearUserRoles(model.userId);
                for (int i = 0; i < model.rolesList.Count; i++)
                {
                    if (!idMan.AddUserToRoleById(model.userId, model.rolesList[i]))
                    {
                        //throw error
                        throw new System.Exception("Error assigning roles");
                    }
                }

                return Json("Successfully Modified " + @model.userId + " roles");
                // TempData["StatusMessage"] = "Successfully Modified " + @model.userId +  " roles";
                //return RedirectToAction("AddUser");
            }
            else
            {
                throw new System.ArgumentNullException("An Error Has occoured, Server recieved a null object");
            }
        }
        catch (Exception e)
        {
            return Json("an Error has occored: " + e.Message);
        }
    }

修改

09:15:04.427 The connection to ws://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/connect?transport=webSockets&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAA2KcGQWCelUiHIES%2B94f0AAAAAAACAAAAAAADZgAAwAAAABAAAAB4nJfh7BfX%2BKhJji2jdWSDAAAAAASAAACgAAAAEAAAAO3Y1yYzc1L%2BbFzIiYywbM4oAAAAmtO5wThTFDXj0RPWp8FFZV357TMNEddKFmYSXZ8RkURiER620X81HRQAAAAKm%2FwECg6JSsHwVKLMMd5WVPF4tQ%3D%3D&requestUrl=http%3A%2F%2Flocalhost%3A53648%2FRoles%2FAddUser%3FselectUser%3Da9860cac-0479-4d1c-9345-b3d18b82698d&browserName=Firefox&tid=10 was interrupted while the page was loading. browserLink:62
09:15:04.485 POST http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/abort [HTTP/1.1 200 OK 2ms]
09:15:04.419 "model: user: f7d1b9e9-f5d1-44dc-b5ba-675c39fe05b9roles: c239bcc1-a145-4a7c-9cb3-716ab7b85b6d,e3690dcf-f239-4479-8f75-d5dde262d16b,e79f4a3d-5f4f-4b9c-a7f3-57fb8569a966" AddUser:259
09:15:04.419 "JSON: {"userId":"f7d1b9e9-f5d1-44dc-b5ba-675c39fe05b9","rolesList":["c239bcc1-a145-4a7c-9cb3-716ab7b85b6d","e3690dcf-f239-4479-8f75-d5dde262d16b","e79f4a3d-5f4f-4b9c-a7f3-57fb8569a966"]}" AddUser:260
09:15:04.486 GET http://localhost:53648/Roles/AddUser [HTTP/1.1 200 OK 299ms]
09:15:04.448 no element found abort:1
09:15:04.962 GET http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/browserLink [HTTP/1.1 200 OK 7ms]
09:15:04.917 TypeError: $.browser is undefined ui.spinner.js:25
09:15:05.066 Use of getPreventDefault() is deprecated.  Use defaultPrevented instead. browserLink:37
09:15:05.174 GET http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/negotiate [HTTP/1.1 200 OK 1ms]
09:15:05.174 GET http://localhost:52054/5c21e1ec9e524f1480756e1a40d25516/arterySignalR/connect [HTTP/1.1 101 Switching Protocols 3ms]
09:15:05.360 GET http://localhost:53648/__browserLink/requestData/84c857e2574e4b5a937a0224ae3bbf29

这是我的html表单:

<form id="rolesSelectForm" class="stdform" action="" onsubmit="return submitForm()">

返回submitForm()并不意味着刷新页面。但由于某种原因它仍然是?

0 个答案:

没有答案