Hello, I have a question about JSON and Javascript

Asked

Viewed 26 times

0

I am trying to create a correspondence management system that generates the reference of the same based on the last ID, and current date, I am using HTML, PHP, JAVASCRIPT, using the attribute Blur of javascript when I click outside the sender field automatically the reference field must be filled in my function has been working normally when running it on localhost with HTTP UNSAFE funcionando com http não seguro

However when I run it on a server with SSL certificate (Cpanel or others) this is HTTPS it does not automatically generate the reference provided by my function com HTTPS não funciona

I don’t know if it has anything to do with my JSON or Javascript, Below is the front code of my form

<script type="text/javascript">
                      $(document).ready(function(){
                        $("input[name='remetente']").blur(function(){
                          var $referencia1 = $("input[name='referencia1']");
                          var $referencia = $("input[name='referencia']");
                          $.getJSON('function.php',{ 
                            remetente: $( this ).val() 
                          },function( json ){
                            $referencia1.val( json.referencia1 );
                            $referencia.val( json.referencia );
                            $referencia = ( json.referencia )
                            Swal.fire({
                              icon: 'info',
                              title: 'Sua Referência: '+$referencia,
                              text: 'ANOTE! não modifique o campo referência',
                            });
                          });
                        });
                      });
                      </script>
                    <form method="POST" action="ad_correspondencia.php" enctype="multipart/form-data">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-4 form-group">
                                    <label for="exampleInputEmail1">Assunto</label>
                                    <input required type="text" required class="form-control" name="assunto" id="exampleInputEmail1" placeholder="Título da Correspondência">
                                </div>
                                <div class="col-md-4 form-group">
                                    <label for="exampleInputEmail1">Remetente</label>
                                    <input required type="text" required class="form-control" name="remetente" id="exampleInputEmail1" placeholder="Entidade que envia">
                                </div>
                                <div class="col-md-4 form-group">
                                    <label for="exampleInputEmail1">Referência</label>
                                    <input required type="text" class="form-control" disabled name="referencia" id="exampleInputEmail1" placeholder="Nº de Referência">
                                    <input required type="hidden" class="form-control" name="referencia1" id="exampleInputEmail1" placeholder="Nº de Referência">
                                </div>
                            </div>

This is the code of my function (Function.php) that it should call

<?php
include_once("../conexao/conexao.php");

function retorna($remetente, $connection){
    $data = date('dmy');

    $consulta_id = "SELECT * FROM correspondencias";
    $resultado_id = mysqli_query($connection, $consulta_id);
    while($ids = mysqli_fetch_assoc($resultado_id)) {
        $ultimo_id = $ids['ID'] + 1;
    };

        $valores['referencia'] = $ultimo_id.'ESP'.$data;
        $valores['referencia1'] = $ultimo_id.'ESP'.$data;

    return json_encode($valores);
}

if(isset($_GET['remetente'])){
    echo retorna($_GET['remetente'], $connection);
}
?>

the interesting thing is that even in HTTPS when I run directly this code it presents me the data returned in JSON

fuction.php funcionando

So I don’t know exactly where the error is, remembering that I’m starting in the area of programming I’m still beginner!

  • already looked if there are errors in the Brower developer tool? can also use the .error to pick up a mistake and see what the problem is

  • Look thank you so much for your contribution, it seems that the external element that was calling in case the Jquery used the unsafe http "http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" logo when changing the url to https it blocked all unsecured external requests in this particular case I changed my requests to https https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.