Show registration without updating page

Asked

Viewed 84 times

0

Good afternoon, I swear I’ve searched everywhere, but all I see is teaching to create chat :'(

I am developing a project (corporate TV style) for the company I work, and the project was serving very well until the headquarters liked this project asked to implement in all other units(including the headquarters) and asked for some things "the most" and it is in these things "the most" that brought me this problem of automatically updating.

1. I’m not a professional, I just know the basics and I get by with what I know;
2. As I learned everything on the Internet the project may not be in standard or current form;
3. I learned everything on the Internet;

The project works like this:

  1. RH inserts the newsletters.
  2. Displays at index(according to unit). Example: localhost/sicc/general/Rj/Bangu (project/controller/function/parameter)
  3. Inside the view (which I called slide) shows all the images for that unit, all for the region(function) the images and all the images that serve for all regions and units

I researched several tools that apparently solve my problem, but as I said at the beginning "I only see teaching to create chat", so I came to Sopt to see if I can get some light or path to solving my problem.

Project:

Controller:

public function rj($unidade = null)
{               
    if (!isset($unidade)) {
        redirect('aplicacao');
    } else {
        if (($unidade === "Caxias") || ($unidade === "caxias")) {
            $unidade = "Caxias";
            $this->load->view('layouts/inicio_slide');
            $this->load->model('slide_model', 'slide');
            $dados['todasR'] = $this->slide->todas_unidade($unidade);
            $dados['fotos'] = $this->slide->todas_fotos_publicas($unidade);
            $this->load->view('slide', $dados);
            $this->load->view('layouts/fim_slide');
        } elseif (($unidade === "Bangu") || ($unidade === "bangu")) {
            $unidade = "Bangu";
            $this->load->view('layouts/inicio_slide');
            $this->load->model('slide_model', 'slide');
            $dados['todasR'] = $this->slide->todas_unidade($unidade);
            $dados['fotos'] = $this->slide->todas_fotos_publicas($unidade);
            $this->load->view('slide', $dados);
            $this->load->view('layouts/fim_slide');
        } elseif (($unidade === "grio") || ($unidade === "GRIO")) {
            $unidade = "Grande Rio";
            $this->load->view('layouts/inicio_slide');
            $this->load->model('slide_model', 'slide');
            $dados['todasR'] = $this->slide->todas_unidade($unidade);
            $dados['fotos'] = $this->slide->todas_fotos_publicas($unidade);
            $this->load->view('slide', $dados);
            $this->load->view('layouts/fim_slide');
        } else {
            redirect('aplicacao');
        }
    }       
}

View:

<?php if((count($fotos) === 0) && (count($todasR) === 0)): ?>
    <div id="slides">
        <div class="slides-container foto-slide">
            <img src="<?php echo base_url('assets/images/wallpaper.jpg') ?>" class="foto-slide" >
        </div>
    </div>
<?php else: ?>
    <div id="slides">
        <div class="slides-container foto-slide">
            <?php foreach($fotos as $foto): ?>
                <img src="<?php echo base_url('assets/fotos/'.$foto['foto']) ?>" class="foto-slide" >
            <?php endforeach; ?>
            <?php if(isset($todasR)): ?>
                <?php foreach($todasR as $todaR): ?>
                    <img src="<?php echo base_url('assets/fotos/'.$todaR['foto']) ?>" class="foto-slide" >
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

Model:

public function busca_regional($id_regional)
    {
        $resultado = $this->db->select('*')
        ->where('id_regional', $id_regional)
        ->get('regionais');
        return $resultado->result();            
    }  
    public function busca_unidade($unidadeL)
    {
        $resultado = $this->db->select('*')
        ->where('unidade', $unidadeL)
        ->get('unidades');
        return $resultado->result();

    }
    public function busca_unidade_todas($id_regional)
    {
        $resultado = $this->db->select('*')
        ->where('id_regional', $id_regional)
        ->where('unidade', 'Todas')
        ->get('unidades');
        return $resultado->result();

    }
    public function todas_unidade($unidadeL)
    {
        $unidade = $this->busca_unidade($unidadeL);
        foreach ($unidade as $uni) {
            $id_regional_local = $uni->id_regional;
        }            
        $regional = $this->busca_regional($id_regional_local);
        foreach ($regional as $reg) {
            $id_regional = $reg->id_regional;
        }
        $toda = $this->busca_unidade_todas($id_regional);
        foreach ($toda as $tod) {
            $id_unidade = $tod->id_unidade;
        }

        $resultado = $this->db->select('*')
        ->from('fotos')
        ->where('id_regional', $id_regional)
        ->where('id_unidade', $id_unidade)
        ->where('publica', true)
        ->get();

        return $resultado->result_array();

    }
    public function todas_fotos_publicas($unidadeL)
    {
        $unidade = $this->busca_unidade($unidadeL);
        foreach ($unidade as $uni) {
            $id_unidade = $uni->id_unidade;
        }

        $resultado = $this->db->select('*')
        ->from('fotos')
        ->where('publica', true)
        ->where('id_unidade', $id_unidade)
        ->get();
        return $resultado->result_array();
    }

I’m sorry if you got confused.

  • What is the expected result?

  • As soon as the person includes the newsletter on the site show automatically in the index

1 answer

0

Not if it will suit you, but here in the company we also use TV Panels that display information that is captured directly from the Database in real time, and to be able to perform this type of update I used the following:

<script type="text/javascript">
  function Ajax() {
    var $http, $self = arguments.callee;

    if (window.XMLHttpRequest) {
      $http = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      try {
        $http = new ActiveXObject('Msxml2.XMLHTTP');
      } catch(e) {
        $http = new ActiveXObject('Microsoft.XMLHTTP');
      }
    }

    if ($http) {
      $http.onreadystatechange = function() {
        if (/4|^complete$/.test($http.readyState)) {
          document.getElementById('SuaDivQueIraAtualizar').innerHTML = $http.responseText;
          setTimeout(function(){$self();}, 3000);
        }
      };
      $http.open('GET', 'index.php' + '?' + new Date().getTime(), true);
      $http.send(null);
    }
  }
</script>

<script type="text/javascript">setTimeout(function() {Ajax();}, 3000);</script>

Obs: This script is in HEAD

All you have to do is add the text Yourfacement for the TAG you want to update in the dashboard, an example of this would be just below the <body> you add a <div id="Geral"> naming her however she wished, in my case I put General so just change the name Yourfacement for General

  • I implemented this code in my project and realized that when you give the 3 seconds it updates the <div> but what is inside the <div> simply goes away. I went to try to understand this code and realized that $http.open('GET', 'index.php' + '?' + new Date().getTime(), true); when commented it does not cause this error, but it does not update the <div>

  • I did this test here 'if ($http.readyState === 4 && $http.status === 200) { Document.getElementById('general'). innerHTML = $http.responseText; setTimeout(Function(){$self();}, 3000); } Else{ Alert($http.readyState); Alert($http.status); Alert('ta foda'); }' '$http.readyState' returns me with value 2(HEADERS_RECEIVED), and dps returns me value 4(DONE) and $http.me status with value 200(OK)

Browser other questions tagged

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