Problems with page refresh in ajax

0

Good afternoon, friends! I'm skating and do not leave the place, the structure of the code is as follows:

insert.php

$.ajax({
   type: 'POST',
   url: 'action.anuncio.php',
   data: dados,
   dataType: 'json',
   success: function(response) {
            location.reload();
      }
});

action.anuncio.php

include_once 'class.anuncio.php';
$anuncio = new Anuncio();
switch ($_POST[]) {
    case 1:
       $anuncio->inserir('informações');
       break;


}

class.anuncio.php

include_once 'conexao.php';
public Anuncio() {
    function listarAnuncios() {}
    function inserir(){
           /*instruçoes sql para gravação*/
           if($result) {
                $response = array('sucess'=>sucess);
                encode_json($response);
            }
      }


}

The code writes and deletes only that it does not refresh the page, I need to press F5 to update, it seems that the ajax trigger is not getting the correct response to reload.

    
asked by anonymous 04.02.2017 / 20:00

1 answer

0

The success function is not being called. The truth is that many reasons can cause this, you have, for example, put a console.log(dados) so that we can see what is being passed as JSON?

Another tip is to replace the code in action.anuncio.php by removing the SWITCH as follows:

if(isset($_POST['chave'])) $anuncio->inserir('informações'); 

Thus preventing undefined errors on the PHP side.

    
06.02.2017 / 14:26