0
hello, I’m having a hard time getting the id generated in php with jquery, so I can send this id to another page, follow the code:
queryInsert.php
$assunto = $_POST['assunto'];
$msg     = $_POST['msg'];
    $query = $db_con->prepare("INSERT INTO tb_tickets (cliente_id,ms_assunto,ms_data,ms_status,ms_read,ms_remetente,ms_destino,ms_mensagem) VALUES (:iduser,:assunto,NOW(),'0','0',:idusers,'1',:msg)");
    $query->bindParam(':iduser', $IdUsuario);
    $query->bindParam(':assunto', $assunto);
    $query->bindParam(':idusers', $IdUsuario);
    $query->bindParam(':msg', $msg);
    if($query->execute()){
        $UltId = $db_con->lastInsertId();
        echo $UltId;
    }else{
        echo 'Error ao solicitar suporte';
    }
crudTicket.js
$(function () {
    var enviandoForm = false;
    $("#emp-SaveForm").submit(function (e) {
                if (enviandoForm) {
                      return false;
                }
                this.disabled = true;
                enviandoForm = true;
                e.preventDefault();
                var FormData = $(this).serialize(); 
                $.ajax({
                  type: "POST", 
                  url: "queryInsert.php",
                  data: FormData
                 }).done(function (data) {
                    $('#emp-SaveForm').trigger("reset");
                    var notification = new NotificationFx({
                    wrapper : document.body,
                    message : ('<div class="alert alert-info">'+data+'</div>'),
                    layout : 'growl',
                    effect : 'scale',
                    type : 'notice',
                    ttl : 6000,
                    onClose : function() { return false; },
                    onOpen : function() { return false; }
                    });
                    notification.show();
                    setTimeout(function() {
                     $(".content-loader").fadeOut('slow', function()
                      {
                        $(".content-loader").fadeIn('slow');
                        $(".content-loader").load('add_ms.php?ms='+data);
                        $("#btn-add").hide();
                        $("#btn-view").show();
                       });
                      });
                    }, 1000).always(function() {
                    enviandoForm = false; //Libera o form
                    this.disabled = false;
                });
                return false;
        }); 
}); 
ms_add.php
<?php
$msGET = $_GET['ms'];
echo $msGET;
All right, what happens? he registers the ticket in the table, he gets the last id, but he gets this guy $(".content-loader").load('add_ms.php?ms='+data); does not work, already in that message : ('<div class="alert alert-info">'+data+'</div>') return me the normal id! thanks for the help!
Makes a
console.log(data);right at the beginning of your done posted what appears– Thiago Santos
No page is loaded on
.content-loaderor the pageadd_ms.phpis loaded, only without the correct value ofms?– Woss
@Thiagosantos, the id usually appears, as the path said in the question!
– JASL
then @Andersoncarloswoss, btn-add some and btn-view appears, for echo $_GET['ms']; it returns me nothing, that echo is at the beginning of the page the rest of the page has some tables and etc, which also do not appear!
– JASL
So apparently it’s a request flaw and not the value of the query string. Your server shows some 404 error in log to the archive
add_ms.php?– Woss
no... look at the page img in the question, simply blank!
– JASL
Ok, you edited by putting the file name as
ms_add.phpbut the load is from the archiveadd_ms.php. The mistake is not that or just got confused when posting here?– Woss
He cited the file name as
ms_add.phpand in the.load()placedadd_ms.php, it was just a clerical error or so in the file name and code?– Max Rogério
error writing sorry! error persists!
– JASL
testing with window.location.href='teste2.php? ms='+data; it works! but I really need load(). teste2.php was a page I created and only put echo $_GET['ms'];
– JASL
I thought you were the
.load(), I don’t know if he interprets the php file using this method. Therefore, it should not be bringing results. Try to turn the return result into json.– Max Rogério