Domanda

<%: Html.ActionLink("Print", "Print", "Print", New With {.id = Model.ID}, New With {.target = "_blank", .class = "print"})%>

How to return to my actionlink's functionality once preventDefault is called? ( the _blank page is not being opened on return)

   $('#NameOfButton').bind('click', function (e) {
                   e.preventDefault(); // Stop click event

                    //Gather Data
                    var data = $(this).parents('form').first().serialize();

                    //Check Data , if saved to DB continue Click functionality
                    $.ajax({
                        url: '<%:Url.Action("Get")%>',
                        cache: false,
                        type: 'POST',
                        data: data,
                        success: function (result) {
                            if (result.Success == true) {
                                //return;
                                return true;
                            } else {
                                //do nothing
                                console.log('false');
                            }
                        }
                    });
                });

Solution:

 $('#NameOfButton').bind('click', function (e) {
                   e.preventDefault(); // Stop click event

                    //Gather Data
                    var el= $(this);
                    var data = $(this).parents('form').first().serialize();

                    //Check Data , if saved to DB continue Click functionality
                    $.ajax({
                        url: '<%:Url.Action("Get")%>',
                        cache: false,
                        type: 'POST',
                        data: data,
                        success: function (result) {
                            if (result.Success == true) {
                            window.location.href = el.attr('href');
                            } else {
                                //do nothing
                            }
                        }
                    });
                });
È stato utile?

Soluzione

You can trigger the event again:

 $('#NameOfButton').bind('click', function (e, skip) {
     if (skip) return; // check param

     e.preventDefault(); // Stop click event

     //Gather Data
     var data = $(this).parents('form').first().serialize();

     var el = $(this);
     //Check Data , if saved to DB continue Click functionality
     $.ajax({
         url: '<%:Url.Action("Get")%>',
         cache: false,
         type: 'POST',
         data: data,
         success: function (result) {
             if (result.Success == true) {
                 console.log('true');
                 el.trigger('click', [true]); // trigger same event with additional param
             } else {
                 //do nothing
                 console.log('false');
             }
         }
     });
 });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top