php - error jquery Autocomplete suggestions is undefined -


i using jquery aucomplete https://github.com/devbridge/jquery-autocomplete/ works fine local , creates problem when using server side script

error img

enter image description here

my code like

html

<div>         <input type="text" name="country" id="autocomplete"/> </div> <div id="selection"></div> 

css

.autocomplete-suggestions { border: 1px solid #999; background: #fff; cursor: default; overflow: auto; } .autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; } .autocomplete-selected { background: #f0f0f0; } .autocomplete-suggestions strong { font-weight: normal; color: #3399ff; } 

script

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="jquery.autocomplete.js"></script> <!-- above js file can downloaded https://github.com/devbridge/jquery-autocomplete/blob/master/src/jquery.autocomplete.js --> <script type="text/javascript">     $('#autocomplete').autocomplete({         serviceurl: 'search.php',         onselect: function(suggestion) {             $('#selction-ajax').html('you selected: ' + suggestion.value + ', ' + suggestion.data);         }     }); </script> 

php page script search.php

<?php     if($_request['query']=='a')     {         echo json_encode(array('ad'=>'adrew','au'=>'australia'));     }     if($_request['query']=='b')     {         echo json_encode(array('br'=>'brazil','ba'=>'bangladesh'));     }     if($_request['query']=='i')     {         echo json_encode(array('in'=>'india','ind'=>'indonasia'));     }     return; ?> 

thanks suggestion.

i got problem

  1. first, gives error suggestions.length
  2. second giving problem suggestion.value.

so below json encoding works fine

echo json_encode(array('suggestions'=>array(array('data'=>'au','value'=>'australia'),array('data'=>'in','value'=>'india')))); 

full php code

<?php     if($_request['query']=='a')     {         echo json_encode(array('suggestions'=>array(array('data'=>'au','value'=>'australia'),array('data'=>'in','value'=>'india'))));     }     else if($_request['query']=='b')     {         echo json_encode(array('suggestions'=>array(array('data'=>'br','value'=>'brazil'),array('data'=>'ba','value'=>'bangladesh'))));     }     else if($_request['query']=='i')     {         echo json_encode(array('suggestions'=>array(array('data'=>'in','value'=>'india'),array('data'=>'ind','value'=>'indonesia'))));     }     else         echo json_encode(array('suggestions'=>array(array('data'=>'nf','value'=>'not found'))));     return; ?> 

thanks whow given precious time once again.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -