javascript - JQuery ajax JSON result to text input value -


i have autocompleter, working fine, wanted add "autofiller" means, if select 1 of "companies" "autocompleter" should results db companies.

the json response is:

[     {         "idfirma": "2222",         "firmenname": "test",         "strasse": "test",         "plz": "",         "ort": "test",         "l‌​and": "",         "webseite": "",         "region": "",         "aktiv": "1"     } ] 

what got far:

$(document).ready(function() {      $(function() {         $( "#firma_neu" ).autocomplete({             source: "./firma_suche.php3",             open: function(event, ui) {                     var firmenname = $("#firma_neu").val();                     },             select: function(event, ui) {                     event.preventdefault();                     $("#firma_neu").val(ui.item.label);                     $("#idfirma_neu").val(ui.item.value);                      // hier muss der if selected aufruf kommen                          var datastring = 'firmenid='+ ui.item.value ;                           $.ajax({                             type: "post",                             data:  datastring,                             url: "./loadfirma.php",                             datatype: "json",                               success: function(result){                                $("#strasse1").val(result.strasse);                               $("#plz1").val(result.item.plz);                               $("#ort1").val(result.item.ort);                               $("#land1").val(result.item.land);                               $("#region1").val(result.item.region);                               }                            });                      },             minlength: 2         });     });  }); 

i correct answer loadfirma.php cant use them...
result.strasse
, result.item.strasse
both wont work

the server side outputting json array. see how surrounded []? result.strasse not exist.

change access first element in array before try access strsse:

$("#strasse1").val(result[0].strasse); 

if expect multiple results can iterate on array:

for(var i=0; i<result.length; i++){     console.log(result[i].strasse) } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -