jquery - cannot populate data in auto complete text field -


              var data_names;      jquery.ajax({      type: "post",      url: 'autocompletehandler.php',      data: {d_name: "d_name"},      datatype: "html",      success: function(data) {        data_names=data;         console.log(data);       }   });  $("#p_name").autocomplete({     minlength: 2,     source:data_names,      focus: function(event, ui) {         $("#p_name").val(ui.item.label);         return false;     },     select: function(event, ui) {           return false;     } })         .data("ui-autocomplete")._renderitem = function(ul, item) {     return $("<li>")             .append("<a>" + item.label + "/" + item.p_gender + "/" + item.p_age + "</a>")             .appendto(ul); }; 

i tried above code populate autocomplete box data.but following error.when print json expected json.but when tried attach autocomplete box.i json array data following error.

        [{"0":"kasun","p_name":"kasun","1":"male","p_gender":"male","2":"02-01-   1988","p_age":"02-01-1988","3":"880020110v","p_nic":"880020110v"}]     uncaught typeerror: property 'source' of object [object object] not function  

not totally sure think if add may towards sloution.

in code change data_names=data; data_names = jquery.parsejson(data); convert json string proper json object autocomplete can handle properly.

var data_names; jquery.ajax(      {         type: "post",         url: 'autocompletehandler.php',         data: {d_name: "d_name"},         datatype: "html",         success: function(data) {               //data_names=data;               data_names = jquery.parsejson(data);               console.log(data);         }  }); 

edit: possibly why autocommit not data have passed it.

from autocommit documentation:

array: array can used local data. there 2 supported formats:      array of strings: [ "choice1", "choice2" ]     array of objects label , value properties: [ { label: "choice1", value: "value1" }, ... ] 

when re-hydtrated data looks this:

array (    [0] => stdclass object     (         [0] => kasun         [p_name] => kasun         [1] => male         [p_gender] => male         [2] => 02-01-   1988         [p_age] => 02-01-1988         [3] => 880020110v         [p_nic] => 880020110v     ) ) 

thats not either of options

so assume autocommit has decided not else assume function, of course not function, incorrectly formatted array, throws exception.

as seem have picked [ { label: "choice1", value: "value1" }, ... ] method, intensionally or not, need change php creates array generates array in correct format autocommit use. when passed php looks this:

{"p_name":"kasun","p_gender":"male","p_age":"02-01-1988","p_nic":"880020110v"} 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -