Welcome Guest, Not a member yet? Register   Sign In
Can't show View with Ajax
#1

Hello! I'm request your help in order to solve a problem that I try to solve several days... 


Things you have to know:

1° The database is in SQL
2° I'm using Ajax to manage the view pages I divided the page in Header, menu, sub menu and content
3° I'm trying to change view page of content.

When the user fill the content page with the info, the submit button call an JS code in helper and create an array to send it a controller function and send it to the database, if the data sended is correct the view page (content) change to a view with the information of the user displayed.

This is part of the controller function:
Code:
public function vistaedit($obj_inv, $array_db){
        if($obj_inv){            
            $edit_view = $this->load->view(base_url()."inventario/edit",$array_db,TRUE);
            $response = array('mensaje' => $edit_view
                          );
            $this->output
                ->set_status_header(200)
                ->set_content_type('application/json', 'utf-8')
                ->set_output(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
                ->_display();
        exit;
        } else {
            echo('ERROR: Uno o mas datos son incorrectos o no estan llenados.');        
        }    
    }



And this is the JS

Code:
   $("#btn_enviar").click(function(){
        var r = confirm("Los datos ingresados no podran ser modificados una vez enviados, presione aceptar si desea continuar");
        if (r == true){
            var url = base_url + "/inventario/insert_inventario"; // El script a dónde se realizará la petición.
                $.ajax({
                  type: "POST",
                  url: url,
                  data: $("#form_inventario").serialize(), // Adjuntar los campos del formulario enviado.
                  success: function(data)
                  {
                      $("#contenido").html(data.mensaje); // Mostrar la respuestas del script PHP.
                  }
                });
            var elem = document.getElementById('btn_enviar');
            //elem.parentNode.removeChild(elem);
            //$("#form_inventario :input").prop("disabled", true);
        }
           return false; // Evitar ejecutar el submit del formulario.
});

I'll appreciate your help so much, I don't know why isn't showing the edit view page, I check if the info is added to the database and is doing it, i tried to see if i can echo the code and isn't working neither...
Reply
#2

If you console.log(data) inside your success callback what does it show?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB