firefox中的DropDown问题

时间:2012-03-16 07:59:20

标签: jquery asp.net-mvc-3

我正在使用下拉标记消息被读取,我已经用ajax调用实现了它,它在IE和Chrome上正常工作但是我在firefox中有问题,从我的Controller重新调整数据后,下面的代码成功函数在IE和IE中有一个参数名称结果 Chrome它运行正常(我发送它的值为true)但是在firefox的情况下它显示错误消息(ReferenceError:结果未定义)我在控制台上检查了这个错误。我正在使用Jquery的1.6版本

 $("#mark").change(function () {
            var message = $('#move_folder').val();
            $.ajax({
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: '/Message/TakeActions'
                            + '?message=' + message,
                dataType: 'json',
                data: $.toJSON(msgsData),
                success: function (result) {
                    if (result == true) {
                        // window.location.href = "/inviteFriends/Index";
                        window.location.reload();
                        DivMsgText("Message moved successfully to" + message);                            
                        $("#selectall").removeAttr("checked");
                        for (var i = 0; i < $('.case').length; i++) {
                            if ($('.case')[i].checked)
                                $('.case')[i].checked = false;
                        }
                    }
                    else {
                        if (message == "mark_read") {
                            alert("Select a message to mark as read");
                        }
                        else {
                            // DivMsgText("Select a message to move");
                            alert("Select a message to move");
                        }
                        $("#divmsg").empty();
                        $("#divmsg").removeClass("success grid_9");
                        $("#divmsg").html().remove();
                    }
                },               
                async: false,
                cache: false
            });
        });

2 个答案:

答案 0 :(得分:1)

尝试替换以下循环:

for (var i = 0; i < $('.case').length; i++) {
    if ($('.case')[i].checked)
        $('.case')[i].checked = false;
}

用这个:

$('.case').removeAttr('checked');

还要确保对查询字符串参数进行正确的URL编码:

'?message=' + encodeURIComponent(message)

此外,您不应在window.location.reload();之后使用任何JavaScript。这个函数就是它的名字所暗示的:它通过导航来重新加载页面,因此可能会停止执行任何后续的j。

还尝试从TakeActions控制器操作中返回有效的JSON对象:

public ActionResult TakeActions()
{
    ...
    return Json(new { status = true });
}

然后在客户端使用以下测试:

success: function(result) {
    if (result.status) {
        ...
    } else {
        ...
    }
}

您的代码存在的问题是我怀疑您只返回了true:

public ActionResult TakeActions()
{
    ...
    return Json(true);
}

将字符串true发送到响应中,该响应是无效的JSON字符串,但是您通过设置dataType: 'json'告诉jQuery您的服务器返回JSON。

还有一句话:您似乎使用了一些message变量,该变量未在您在问题中显示的范围内的任何位置声明。这个变量实际上是在哪里声明的吗?它是否在您的函数中可以访问的范围内声明?

答案 1 :(得分:0)

window.location.reload()之后的代码;不会被执行。在某些浏览器中工作的原因是你的window.location.reload();不在那里工作,你应该使用window.location.reload(true);但是在成功功能结束时,可能会暂停一段时间......

相关问题