Expert Refresh

Autocomplete

Ajax

Request
Ajax post
Ajax cross domain
Autocomplete
Combobox related


0.0% 100%
0 pages 29 questions
No questions today


<?php if (@$_GET['keyword']) { $arr = array('Arad', 'Alba', 'Bucuresti', 'Brasov', 'Covasna', 'Cluj'); $matches = array(); foreach($arr as $v) { if (stripos($v, $_GET['keyword']) === 0) { array_push($matches, $v); } } echo json_encode($matches); die; } ?> <script type="text/javascript" src=""></script> <script type="text/javascript" src=""></script> <link href="" media="screen" rel="stylesheet" type="text/css" /> <input type='text' id='editable_autocomplete' name='editable_autocomplete'> <script type='text/javascript'> // autocomplete $(function() { var cache = {}; var lastXhr; $( "#editable_autocomplete" ).autocomplete({ minLength: 1, source: function( request, response ) { var term = request.term; if ( term in cache ) { response( cache[ term ] ); return; } lastXhr = $.getJSON( "test.php?keyword="+term, function( data, status, xhr ) { cache[term] = data; if ( xhr === lastXhr ) { response( data ); } } ); } }); }); </script>


References



n/a