JSON Success URL

0

I have a web application in PHP where I generate income to an item. I can assign movements to this item. I do it with a FORM POST . Besides I have a button where I can eliminate that assignment.

This method was done with JSON .

     $(document).ready(function() {

         $('.view_data').click(function() {
             var code = $(this).attr('id');
             var val = $('#valor').val();
             $.ajax({
                 type: 'POST',
                 url: 'JSON/deleteJSON.php',
                 data: {
                     'code': code,
                     'val': val
                 },
                 success: function(data) {
                    location.reload();

                     }
             });
             // End AJAX function
         });
     });
 </script>

In my PHP

<?php
include_once '../include/conexion.php';
$codmenu = $_POST['code'];
$id = $_POST['val'];


$sql = "DELETE FROM ACT_FKAgenda WHERE id_fkagenda =$codmenu";
  $resultt = mysqli_query($conn, $sql);
if($resultt) {

   header("Refresh:0; url=../add-horas.php?id=$id&Borrado");

} else {

  header("Refresh:0; url=../add-horas.php?id=$id&ERROR");
}
?>

When I delete it, it refreshes me on the same page, since in JSON SUCCESS I have the function location.reload(); but my question is if I can do something like this in JSON

header("Refresh:0; url=../add-horas.php?id=$id&Borrado");

Where it refreshes in the page of the item that I am assigned movements and apart I add the $Borrado to the URL so I can use a $ _GET and show a message.

I hope to have explained myself well. Greetings.

    
asked by MoteCL 30.08.2018 в 20:50
source

1 answer

1

You can add the message instead of the window reload

$.ajax({
     type: 'POST',
     url: 'JSON/deleteJSON.php',
     data: {
         'code': code,
         'val': val
     },
     success: function(data) {
        window.location.href = window.location.href + '&borrado=1'

     }
});

Although I do not see much sense in making an ajax call if at the end of the account you end up reloading the page, you could do it directly with the POST and redirect to the same page with the parameter, or display the desired message with js from the success of ajax.

    
answered by 30.08.2018 / 21:06
source