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

94
Visualizações
Displaying an Alertbox from PHP Controller class

Currently I'm in my controller and I have placed a check in the controller. Basically checking if the value of a particular field is 0 or not. Now if it is 0, I want to display an alert popup via my controller. To do this I've tried the following code:

public function status($status){ 
    if($this->input->post('id')){
        foreach($this->input->post('id') as $key => $id):
            $check_emirate = $this->listings_model->check_emirate($id);
            if($check_emirate->emirate == 0){
                echo "<script>alert('This card was not approved.');</script>";
            }else{
            $data=array('status'=>$status);  $updated=$this->listings_model->update($data,array(),$id); 
    }
        endforeach;     
    } 
    return true;
}

Now it is entering my if condition, but it doesnt show me the popup.

This is the AJAX call I'm making to enable this function:

$(".status").click(function(e) { chagestatus($(this)); }

function chagestatus(obj){ 
  if($('.chkbx').is(':checked') == true){
    $.ajax({
      type: "post",
      dataType: "json",
      async:false,
      url: "<?php echo site_url('listings/status'); ?>/"+obj.data('val'),
      data: $(".chkbx:checked").serialize(),
      success: function(result) {}
    });
  }
}

Another thing I've tried here is using json_encode this way:

if($check_emirate->emirate == 0){
                $data = "<script>alert('This card was not approved, Thanks.');</script>";
                echo json_encode($data);
            }

  success: function(result) {
    result = JSON.parse(result);
  }

But this also didn't give back any response.

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

0

If the function in your controller works well, then you need append your result from server to your DOM:

    success: function(result) {
        $('body').append(result);
    }
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