【问题标题】:alert box not working in ajax success (asp.net)警告框在 ajax 成功(asp.net)中不起作用
【发布时间】:2016-10-06 17:53:51
【问题描述】:

我在输入框 onclick 事件中使用 ajax 调用。 当我在 ajax 成功中调用 alertbox 时,它不起作用,但 console.log 运行良好。 请帮帮我。

在我看来

<input id="extention" type="text" value="" onkeyup="SetExtention(event, this.value); return false;" class="form-control terminal_id" />

我的功能

    function SetExtention(e, item) {
        console.log("SetExtention");
        e.preventDefault();

        if (item != "") {
            if (e.keyCode == 13) {   //Enter Event

                var inputLine = $('#extention').val().split(',');

                if (inputLine.length == 0)
                    return;
                else {
                    $('#hdnLastExtention').val(inputLine[inputLine.length - 1]);

                    for (var i = 0; i < inputLine.length; i++) {

                        $.ajax({
                            url: urls,
                            type: 'GET',
                            dataType: 'json',
                            data: {
                                ID: inputLine[i]
                            },
                            cache: false,
                            async:false,
                            success: function (result) {
                               alert("aaaaaaaa");
                               console.log("aaaaaa");

                                if (result.isSuccess == false) {

                                    doing some work...
                                }

                                if ($('#hdnLastExtention').val() == result.inputData)
                                {
                                    alert("alert box doesn't appear.");
                                    console.log("alert box doesn't appear.");
                                }

                            },
                            error: function (request, error) {
                                console.log("It has error");
                            }
                        });
                    }
                }
            }

        }
}

最后,这是控制台的结果(我附上图像以明确结果。)

我可以看到控制台日志,但警告框不起作用。

Reference Image

【问题讨论】:

  • 我只是忘记通知我在 Chrome 中进行了测试。我应该只使用 Chrome 浏览器。
  • Async false 不会改变任何东西
  • 我突然解决了这个问题。我尝试删除 chrome 历史记录,它运行良好。我不知道为什么,但我猜是 cookie 或兑现数据问题。

标签: asp.net ajax


【解决方案1】:

当您勾选“停止此页面创建弹出窗口”的确认框时会发生这种情况。

请尝试,关闭标签并打开一个新窗口并尝试。

【讨论】:

    【解决方案2】:

    确保脚本标签中有 type="text/javascript" 属性。

    例如;

    <script  type="text/javascript">
    
        // Your function
    
    </script>
    

    【讨论】:

      猜你喜欢
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多