0
I can not return anything .. when I test instead of the city field and erase there it returns but with the name of the city it does not return has data limit for a CMB?
$(document).ready(function() {
$('#carrEst').change(function(e) {
$('#carrCid').empty();
var id = $(this).val();
$.post('../include/carrCid.php', {ufid:id}, function(data){
var cmb = '<option value="">Selecione a Cidade</option>';
$.each(data, function (index, value){
cmb = cmb + '<option value="' + value.cidadeid + '">' + value.cidaden + '</option>';;
});
$('#carrCid').html(cmb);
}, 'json');
});
});
PHP
if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) &&
$_SERVER["HTTP_X_REQUESTED_WITH"] === "XMLHttpRequest") {
$conexao = mysqli_connect('localhost', 'root', '', 'rhsystem') or
die(mysqli_error($conexao));
$ufid = filter_input(INPUT_POST, 'ufid', FILTER_SANITIZE_NUMBER_INT);
//$ufid = 48;
if ($ufid) {
$query = mysqli_query($conexao, "SELECT idCidade, cidade FROM tbCidade WHERE fkEstado =" . $ufid . "");
$linhas = array();
while ($jm = mysqli_fetch_array($query)) {
$linhas[] = array(
"cidadeid " => $jm["idCidade"],
"cidaden" => $jm["cidade"],
);
}
echo json_encode($linhas);
}
}
HTML
<!DOCTYPE html>
TODO Supply a title
<div class="row">
<div class="item form-group">
<label id="estado" class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Estado <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-2 col-xs-12">
<select id="carrEst" >
</select>
</div>
</div>
<div class="item form-group">
<label id="cidade" class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Cidade <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-2 col-xs-12">
<select id="carrCid" >
</select>
</div>
</div>
</body>
Code to save to Javascript database
$("document").ready(function () {
$("#btngravar").click(function () {
$.post("../include/cadfunc.php", {oper: "1", nome: $("#txtnome").val(),cpf: $("#txtcpf").val(),
endereco: $("#txtendereco").val(), cep: $("#txtcep").val(),complemento: $("#txtcomplemento").val(),bairro: $("#txtbairro").val(),
dtNasci: $("#dtaNascimento").val(), sexo: $("#cmbSexo").val(), email: $("#txtemail").val(),dtaAdm: $("#dtaAdmissao").val(), UF: $("#carrDpto").val(),
cidade: $("#carrCid").val(), dpto: $("#carrDpto").val(), cargo: $("#carrCarg").val(), salario: $("#txtsalario").val(), status: $("#carrStatus").val()} ,function (data) {
var items = [];
i = 0;
alert(data.tipo);
});
});
});
PHP code
<?php
include "conexao.php";
$oper = $_POST["oper"];
switch ($oper) {
case 1:
inserir($_POST["nome"],$_POST["cpf"],$_POST["endereco"],$_POST["cep"],
$_POST["complemento"],$_POST["bairro"],$_POST["dtNasci"],$_POST["sexo"],
$_POST["email"],$_POST["dtaAdm"],$_POST["UF"],$_POST["cidade"],
$_POST["dpto"],$ _POST["cargo"],$_POST["salario"],$_POST["status"],$conn);
break;
default:
$data = '{"tipo": "sucesso"}';
echo $data;
}
function inserir($nome,
$cpf,$endereco,$cep,$complemento,$bairro,$dtNasci,$sexo,$email,$dtaAdm,
$UF,$cidade,$dpto,$cargo,$salario,$status,$conn) {
$sql = "CALL InserirFunc ( '".$nome."', '".$cpf."', '".$endereco."',
'".$cep."', '".$complemento."', '".$bairro."', '".$dtNasci. "',
'".$sexo."', '".$email."',' ".$dtaAdm."', ".$UF.", ".$cidade.", ".$dpto.",
".$cargo.", ".$salario.", ".$status.")";
mysqli_query($conn,$sql);
$data = '{"tipo": "sucesso"}';
echo $data ;
}
?>
Hello Somdesp, could you post the codes instead of images? makes it easy for the person to test and help you.
– William Cézar
ready .. first time I do a post here was not managing to do by code now I managed to
– Somdesp
Is there a city with an emphasis on the case?
– Don't Panic
yes. several cities
– Somdesp
Try to put it like this:
"cidaden" => utf8_encode($jm["cidade"])
– Don't Panic
Now it worked. Thank you very much
– Somdesp