Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
Laravel PHP script binded with a dialog

I am new to the web development and to Laravel. I am creating a local web application that will run on one pc using windows. I have a script in it that reads data from the camera device. This script is started when the user press a button. this button opens a dialog and creates an ajax call to get data from the php script.

What I need here is to make a cancel button in the dialog that will terminate the calling of php script.

What happens so far? I create an ajax call from the cancel button two. But this called PHP script is never executed until i turn the other script off manually (shutting down my camera).

I am ready to change the design idea. I am just stuck now and don't have enough experience to decide what to do.

here is the script so far:

  <script>
    var updateBtn = document.getElementById("update");
    var favDialog = document.getElementById("favDialog");
    var cancelBtn = document.getElementById("cancel");
    updateBtn.addEventListener("click", function onOpen() {
      favDialog.showModal();
      $.ajax({
        type: 'GET',
        url: '/getBar',
        data: '_token = <?php echo csrf_token() ?>',
        success: function(data) {
          window.location.assign("/view?qr=" + data);
        }
      });
    });

    cancelBtn.addEventListener("click", function onOpen() {      
      $.ajax({
        type: 'GET',
        url: '/closeApp',
        data: '_token = <?php echo csrf_token() ?>',
        success: function() {}
      });
    });
  </script>

EDIT: ajax call abort() does work.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think what you are looking for is abort(), assuming that you are using jQuery 3.x.

Most of the jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object.

See the documentation:

  • abort. If the request has been sent already, this method will abort the request

    <script>
      var updateBtn = document.getElementById("update");
      var favDialog = document.getElementById("favDialog");
      var cancelBtn = document.getElementById("cancel");
    
      var request = null;
      updateBtn.addEventListener("click", function onOpen() {
        favDialog.showModal();
        request = $.ajax({
          type: 'GET',
          url: '/getBar',
          data: '_token = <?php echo csrf_token() ?>',
          success: function(data) {
            window.location.assign("/view?qr=" + data);
          }
        });
      });
    
      cancelBtn.addEventListener("click", function onOpen() {
        if (request != null) {
          request.abort();
        }
      });
    </script>
    
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda