如何实现递归调用--jquery

时间:2014-06-23 18:56:02

标签: javascript jquery asp.net-mvc modal-dialog

我有一个自定义创建的对话框模块。 我正在将mvc view Cart传递给此模块。 cart view有一个名为'Create New Contat'的链接,使用ajax调用点击view(Cart)将被另一个view(Contact替换“。 contact view有一个名为cancel的按钮。当用户点击取消时,旧的view(Cart)将替换现有的view(contact。 我面临的问题是在更换视图后,视图上没有任何链接或按钮工作。 有些人可以指示我采取更好的方式来做到这一点。

下面粘贴的是代码。

    $(document).on('click', '.ddlCart li', function(e) {


            var ddlselectedVal = $(this).attr('id');
            var selectedListinsCount = selected_Listings.length;
            var SelectedMlsnums = selected_Listings.join();
            var agentId = $("#AgentId").val();

            var Action;

            var EnvironmentURL = $("#EnvironmentURL").val();


            var postData = { AgentId: agentId, Mlsnums: SelectedMlsnums, ActionTypeValue: “PreAddToCart” };

            var close = function (event, ui) {
                 $('#dvModalDialog').dialog("close");
                          }
            var open = function (event, ui) {    

                var url = EnvironmentURL + "MLSReports/Stats/SearchContacts";


                $("#btncart_cancel").on("click", function () {
                    $('#dvModalDialog').dialog("close");
                });

                $("#btncart_submit").on("click", function () {

                    var url = EnvironmentURL + "MLSReports/Stats/Cart";

                    //Send the data using post and put the results in a div                   
                    $.post(url, {
                        AgentId: agentId, Mlsnums: SelectedMlsnums, ActionTypeValue: "AddToCart"
                    },
                        function (data) {
                            // Replace current data with data from the ajax call to the div.         
                            $("#dvModalDialog").empty().append(data);
                        });                 

                });

                $("#lnkCreateNewcart").on("click", function () {

                    var url = EnvironmentURL + "MLSReports/Stats/Cart";
                    //Send the data using post and put the results in a div                   
                    $.post(url, {
                        ActionTypeValue: "preAddorEditContact"
                    },
                        function (data) {
                            //debugger;
                            // Replace current data with data from the ajax call to the div.         
                            $("#dvModalDialog").empty().append(data);


                            $("#btnCancelContact").on("click", function () {
                                  ////********** replace the view (Contact) with the view (Cart).
// In the cancel event I am loading the previous page.I am having problem here. after post none of the controls work.  

                                $.post(url, {
                                ActionTypeValue: "PreAddToCart"
                                   },
                            function (data) {
                                //debugger;
                                // Replace current data with data from the ajax call to the div.         
                                $("#dvModalDialog").empty().append(data);
                            })
                              }); 
                       });
                });

                };
                if (ddlselectedVal == "AddtoCart") {
                    var rd = Mod.ReportsDialog({ title: 'Add To Cart', close: close, open: open });
                    rd.url = EnvironmentURL + "/MLSReports/Stats/Cart";
                    rd.targetElement = '#dvModalDialog'// '#dvSendEmail'
                    rd.formName = '#frmCart'
                    rd.postData = postData
                    rd.open();
                }

            });

0 个答案:

没有答案