skazipreto Posted February 18, 2016 at 12:00 PM Report Share #593644 Posted February 18, 2016 at 12:00 PM (edited) Boas Malta. Tenho este código - <?php session_start(); include 'conexao.php'; //$id_pro=$_POST["id_propriedade"]; $id_questao=$_POST["id_ques"]; $query=mysqli_query($db,"select id_questoes, nome_opcao from opcoes where id_questoes=$id_questoes"); $xx=array(); while ($event = mysqli_fetch_assoc($query)) { $xx[]="text_op".$event['nome_opcao']; } echo json_encode($xx); ?> depois de ter os dados, o que pretendia era mostrar esses dados em inputs. e para isso tenho este codigo, $.ajax({ url:"getop.php", method:"POST", dataType: 'json', data:{id_ques:id_p}, success:function(response){ var id_p= $('#lista_questoes option:selected').val(); document.getElementById("hs").value=id_p; var i = 0; for (i = 0; i< response.length; i++) { $("#text_op").val(response[i].strasse); }; }, error:function(error){ console.log(error); } }); Ou seja consoante os dados que receba da BD queria coloca-los num(s) input(s). mas com este código n consigo mostrar. Podem me dizer o que estou a fazer mal ou outras sugestões??? Cumprimentos Edited February 19, 2016 at 12:26 AM by thoga31 Tags code + GeSHi Link to comment Share on other sites More sharing options...
tiago.f Posted February 18, 2016 at 01:26 PM Report Share #593648 Posted February 18, 2016 at 01:26 PM (edited) Oi, no $ajax, o dataType indica o tipo de dados da resposta, não o tipo de dados que submetes. no parametro 'data' do $ajax, em vez de data:{id_ques:id_p} tenta data:"id_ques="+id_p Edited February 19, 2016 at 12:27 AM by thoga31 Tags code + geSHi Link to comment Share on other sites More sharing options...
skazipreto Posted February 18, 2016 at 03:26 PM Author Report Share #593650 Posted February 18, 2016 at 03:26 PM (edited) Já fiz essa alteração. mas agora mostra no input isto " [object Object] " . Este código está bem ? $("#text_op").val(response[i].strasse); Este é o código html onde quero mostrar os valores <input class="form-control" type="text" id="text_op" name="text_op[]" value=""> Edited February 19, 2016 at 12:27 AM by thoga31 Tags code + GeSHi Link to comment Share on other sites More sharing options...
skazipreto Posted February 18, 2016 at 06:39 PM Author Report Share #593657 Posted February 18, 2016 at 06:39 PM Já consegui resolver. muito obrigado pela ajuda tiago.f Cumprimentos 1 Report Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now