Example #1
0
 /**
  * @abstract Executa o comando para retornar os dados 
  * em JSON para o AJAx
  * @param $xjson
  * @return String JSON
  */
 public function responde($xjson = false)
 {
     $msg = Sistema_Mensagem::instanciar();
     $json = new Sistema_Json();
     //Adiciona as Variáveis adicionais na resposta do Ajax
     if ($this->_vars != null) {
         foreach ($this->_vars as $campo => $valor) {
             $respostajax[$campo] = $valor;
         }
     }
     $respostajax['qtd'] = $msg->getMensagem(true) ? count($msg->getMensagem(true)) : 0;
     $respostajax['mensagem'] = $msg->getMensagem();
     $respostajax['tipo'] = $msg->getTipo();
     $respostajax['campos'] = $msg->getCamposErro();
     $respostajax['erro'] = $msg->temErro() ? 1 : 0;
     $respostajax['alerta'] = $msg->temAlerta() ? 1 : 0;
     if (is_array($this->_botoes)) {
         foreach ($this->_botoes as $k => $v) {
             $respostajax['botao'][] = $v;
         }
     }
     $resposta = $json->encode($respostajax);
     $resposta = str_replace("\n", '<br />', $resposta);
     # Verifica se irá retornar junto com o cabeçalho HTTP
     if ($xjson) {
         header("Content-Type: text/html; charset=iso-8859-1");
         header('X-JSON: ' . $resposta);
     } else {
         # Retorna como texto
         header("Content-Type: text/html; charset=iso-8859-1");
         echo $resposta;
     }
 }
Example #2
0
<?php

# inclui o config
include '../../config.php';
$valor = substr(strtoupper($_POST['uf']), 0, 2);
$sql = sprintf("SELECT cid_cod,cid_nome FROM cidade WHERE est_cod='%s'", $valor);
$dados = Sistema_Conecta::Execute($sql, PDO::FETCH_ASSOC);
$json = new Sistema_Json();
die($json->encode($dados));
$json = new Sistema_Ajax();
$json->addVar($dados);
$json->responde(true);