Jump to content

[Ajax/PHP] Inserir dados de BD num input


skazipreto

Recommended Posts

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 by thoga31
Tags code + GeSHi
Link to comment
Share on other sites

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 by thoga31
Tags code + GeSHi
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.