javascript - JQUERY - JSON Result assign it to pre populate form fields on when select is selected -


i have requirement form business save searches, allowing users use saved search data , rerun search. have saved search in database json object. problem when users select saved search via using select - dropdown, form should pre populates selections saved search. when trying alert key value within populate function - show key 0 , value whole json object. missing here ?

sample of returned json request database looks like: {"affects":["153","503","537"],"suspect":["101","108"],"state":[],"zip_code":[],"analysis_date_max":["",""],"last_modified_date_min":["",""]}

here existing code: //start of problem code

function populate(frm, data) {         var obj  = $.parsejson(data);         //alert (data);         //alert (frm);          alert (obj);         $.each(obj, function(key, value){             alert(key + ' ' + value);         $('[name='+key+']', frm).val(value);        }); }  // end of problem code     $('#search_dataselect').on('change', function()     {        getsearchdata(this.value);      });      function getsearchdata(search_id) {      if (!isnan(parseint(search_id))) {          $.ajax({             type: "get",             url: "/index.cgi?p=json&t=savedsearch&search_id="+search_id,              success: function(result){             var data  = result;             populate('#formsearch',data);              },         });     }             return false;     } 

it appears data not serialized. try this:

success: function(result) {  var data  = json.stringify(result); populate('#formsearch', data);  } 

an example using json.stringify()

https://jsfiddle.net/3u6mrft1/


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -