0

This is my code, I implemented the e.preventDefault but it was not working and the page will still go to top.

$('#SaveAnswerButton').click(function (e) {
            e.preventDefault();
            let obj = {};
            let formDta = $("#answerform").serialize();
                  
            $.ajax({
                url: '@Url.Action("SaveAnswer", "AnswerPage")',
                data: formDta + '&currentAction=' + 0 + '&guid=' + "@guid",
                type: 'POST',
                datatype: "json",
                success: function (data) {
                    if (typeof data.expired != "undefined") {
                        window.location = data.expired;
                    }
                    else {
                        var urllink = '@Url.Action("AnswerPage", "AnswerPage")?action1=' + data.action1 + '&guid=' + "@guid";
    
                        if (data.status === 0) {
                            Swal.fire({ title: 'Saved Successfully', type: 'success', showCancelButton: false, showConfirmButton: false });
                            window.location.replace(urllink, 4000);
                        }
                    }
    
                }
            });
        });
gudeThings
  • 13
  • 3

0 Answers0