简体   繁体   English

ajax调用后无法运行jquery.asp .net mvc3(Razor)

[英]jquery does not work after ajax call.asp .net mvc3(Razor)

I am doing a post back to get a partial view using ajax following is the code I am using to render the partial view in a div called 'DivSearchGrid'. 我正在回发帖子以使用ajax获得部分视图,以下是我用来在称为“ DivSearchGrid”的div中呈现部分视图的代码。

 <script type ="text/javascript" >
       $('#Retrieve').click(function () {
           $('form').get(0).setAttribute('action', 'Search');
           //                      $('form').submit();
           var formSubmit = $('form');
           var datTab;
           $.ajax({
               url: "/AuthorityGrid/Search",
               type: "POST",
               data: formSubmit.serialize(),
               success: function (data) {
                   datTab = data;
               },
               complete: function () {
                   $('#DivSearchGrid').html(datTab);

               }

           })
           return false;
       });
   </script>

The action method in the controller returns a grid with new values. 控制器中的action方法将返回带有新值的网格。 my problem is that after the ajx call is complete the other jquery events in my page stop working. 我的问题是在ajx调用完成后,页面中的其他jquery事件停止工作。 The code for some events is as follows. 某些事件的代码如下。

<script type="text/javascript">

        $(function () {
            //$('th[scope|="col"]').resizable();
            $("#resultGrid > tbody").selectable({
                selected: function (event, ui) {
                    if (ui.selected.cells != null) {
                        var strAmount = ui.selected.cells(6).innerText;
                        var Amount = strAmount.replace(/,/gi, "");
                        var keyValue = "AuthorityLevel1=" + ui.selected.cells(11).innerText + ",AuthorityLevel2=" + ui.selected.cells(12).innerText + ",TcmAccount=" + ui.selected.cells(2).innerText + ",TcmType=" + ui.selected.cells(10).innerText + ",Rating=" + ui.selected.cells(5).innerText + ",Amount=" + Amount + ",AuthorityGridKey=" + ui.selected.cells(9).innerText + ",CagName=" + ui.selected.cells(3).innerText
                        var keyValModify = ui.selected.cells(11).innerText + "," + ui.selected.cells(10).innerText + "," + ui.selected.cells(12).innerText + "," + ui.selected.cells(5).innerText + "," + ui.selected.cells(2).innerText + "," + Amount + "," + ui.selected.cells(3).innerText + "," + ui.selected.cells(9).innerText
                        $('#CancelViewParam').val(keyValue);
                        $('#ModifyViewParam').val(keyValModify);

                    }
                }
            });
        });
    </script>

this function selects a row from the grid and puts the selected values in a hidden field. 此函数从网格中选择一行,并将所选值放在隐藏字段中。

Also a function to open popups is not working after the ajax call.code for this function. 同样,打开弹出窗口的功能在此功能的ajax call.code之后不起作用。

$(function () {
    $("#DivSearch").dialog({ autoOpen: false, height: "600", width: "600", dialogClass: "myRatingHelp", modal: true });
    $('#bRatingHelperDivSearch').live('click',function () { $('#DivSearch').dialog('open'); });
    $('#DivSearchRating_bOk').click(function () {
    $("#InputAuthorityGridSearch_Rating").val($("#hidRating").val());
    $("#DivSearch").dialog('close');
    });
    $('#DivSearchRating_bCancel').click(function () {
    $("#DivSearch").dialog('close');
    });
    });

All these functions work perfectly well before the ajx call but all stop working after the call,can someone help? 所有这些功能在ajx调用之前都能很好地工作,但是在调用之后全部停止工作,有人可以帮忙吗? I am not using webforms , I am using asp.net mvc3(razor) 我没有使用webforms,我正在使用asp.net mvc3(razor)

I assume the code that doesn't work any more does not get called after the ajax call? 我假设不再起作用的代码在ajax调用之后没有被调用? It seems likely that your code still works, but isn't triggered anymore. 您的代码似乎仍然可以工作,但不再被触发。 As the content of the data grid changes, your added handlers/events/... will not be boud to any item anymore. 随着数据网格内容的更改,您添加的处理程序/事件/ ...将不再绑定到任何项目。

Have you tried re-executing the code after the ajax-call has been completed, so that the handlers/events/... are bound to the new content? 您是否尝试过在ajax调用完成后重新执行代码,以便将处理程序/事件/ ...绑定到新内容?

Also: the .live() code is the only part that should always work, in theory. 另外:从理论上讲,.live()代码是应始终起作用的唯一部分。 However, live is a deprecated function. 但是,live是不推荐使用的功能。 Suggestions are to use .delegate() before jQuery 1.7 or .on() after jQuery 1.7 建议在jQuery 1.7之前使用.delegate()或在jQuery 1.7之后使用.on()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM