I need to parse JSON in jQuery autocomplete function. I used following code.
jQuery("#name").autocomplete( '<?php echo HTTP_PATH.'/songs/sss'; ?>', {
multiple: true,
mustMatch: true,
matchContains: true,
autoFill: false,
dataType: "json",
});
My cake Controller regarding that is
public function sss(){
$condition = array('Poet.status'=>'3');
$poet_name = $this->Poet->find('list', array('conditions' => $condition));
//pr($poet_name); exit;
echo json_encode($poet_name);
$this->autoRender = false;
}
I am receiving my data as simple array. Means
Array(
[1]=>Abc,
[15]=>Xyz
[56]=>MNK
[77]=>skl
[85]=>qw5s
)
How can I parse read and format following returned array with jquery.
JQuery Autocomplete requires label and/or value, where the label is displayed. Unless there is a need to parse json on the client side, I would do it on the server-side (simpler to me).
Being that you could insert the following:
By formatting on the server-side, the json is preformatted for the json autocomplete making the markup on smaller resulting in a quicker upload of the page and less clutter.