Jquery AJAX Post在代码后面没有命中方法

时间:2014-04-18 13:51:59

标签: javascript jquery asp.net ajax

我有一个使用jQuery 1.8.2的ASP.NET网站。我有一个对话框,列出了DB中的UserReporting设置是否显示列。用户可以通过单击打开对话框的更改列按钮来更改此项 - 然后是可用列和当前列的列表,用户可以从一侧拖放到另一侧。

对话框按钮下的“更新”按钮中的代码无法正常工作 - “Hello”警报会触发,但如果我在我的ashx处理程序中设置断点,它就永远不会被击中?

        $("#UserReportSettings").dialog({
            resizable: false,
            autoOpen: false,
            height: 600,
            width: 525,
            modal: true,
            buttons: {
                "Update Columns": function () {
                    var columns = [];

                    $('#currentColumnsList').each(function () {
                        // this is inner scope, in reference to the .phrase element
                        var column = '';
                        $(this).find('li').each(function () {
                            // cache jquery var
                            var current = $(this);
                            // check if our current li has children (sub elements)
                            // if it does, skip it
                            // ps, you can work with this by seeing if the first child
                            // is a UL with blank inside and odd your custom BLANK text
                            if (current.children().size() > 0) {
                                return true;
                            }
                            // add current text to our current phrase
                            column += (current.text() + ',');
                        });
                        // now that our current phrase is completely build we add it to our outer array
                        columns.push(column);
                    });

                    $.ajax({
                        type: 'POST',
                        url: '/MyWebsite/Handlers/UpdateUserReportingSettings.ashx',
                        data: { reportingSettings: columns.join() },
                        beforeSend: function (xhr, opts) {
                        },
                        success: function (data) {
                            alert("Hello");
                            window.top.location.href = "landing.aspx";
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            alert('error' + xhr.responseText);
                       }
                    });

                    $(this).dialog("close");
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

编辑 - 关注弓箭手评论

如果我将 localhost / Handlers / UpdateUserReportingSettings.ashx 粘贴到浏览器中,我可以在我的处理程序中点击断点。

所以在ajax调用中将我的URL更改为:

url: '/MyWebsite/Handlers/UpdateUserReportingSettings.ashx',

并进行了移位刷新以重新加载页面的js并点击断点。

0 个答案:

没有答案