1

I have a problem in my code. I make a simple form using the checkbox. when the checkbox is clicked, the data will be validated. then if validation is successful then the checkbox will still be checked and window.location will change, if it fails, the checkbox will be unchecked and window.location will change.

$(document).ready(function () {
    $(".publish").click(function () {
        var data = $(this).attr("data-identity");
        if ($(this).attr('checked', true)) {
            var url = "/Manager/AdminApprove/";
        }
        $.ajax({
            url: url + data
        }).done(function (data) { //refresh after click
            $(document).change(function () { 
                if ($(".publish").prop('checked', true)) { //if data succes validation
                    var error_succes = "Succes";
                }
                else {
                    var error_succes = "Error";
                }
                window.parent.location = "/Manager/Admin?" + error_succes;
            });
        });
    });
});
Setiawan
  • 33
  • 7
  • try location.href = your_url and let me know what you get. And alos why you are using document change inside done method ? data will be returned from the server – thedudecodes Mar 06 '19 at 05:48
  • @pawankumar : the url that I get is manager/admin. So, what should I do? help – Setiawan Mar 06 '19 at 06:44
  • do location.href = "manager/admin?data="+error_succes; try using this – thedudecodes Mar 06 '19 at 06:47
  • @pawankumar the url that I get is manager/admin. still the same – Setiawan Mar 06 '19 at 07:21
  • url cannot change – Setiawan Mar 06 '19 at 07:23
  • I think u shoudl check what's in data remove document on change from done method. and from server side send data . in if condition check what is in data (if you are sending sending true on success and false for failer you can check that in if else and decide what to do). check below example https://stackoverflow.com/questions/16076009/confused-on-jquery-ajax-done-function – thedudecodes Mar 06 '19 at 07:25
  • @pawankumar thanks, very helpful – Setiawan Mar 06 '19 at 10:03
  • then upvote the comments and post the actual answer so other people can find it. – thedudecodes Mar 06 '19 at 10:21

1 Answers1

0
 var error_succes = "";
            if (data == "True"){
                var error_succes = "Succes";
            }
            else {
                var error_succes = "Error";
            }
            window.parent.location = "/Manager/Admin?" + error_succes;
Setiawan
  • 33
  • 7