Hello, I will try to help you.
First of all, you need to pass the correct link to the autocomplete function. In most browsers you can do RightClick->InspectElement anywhere. A window opens. There should be a tab "Network". By typing into the textbox, a request should be made and you will see where it goes. If there is no request, it probably means that you have errors in your javascript.
If the request is correct, you have to take care about the method, get or post.
The server should answer with a json formated array of items. The items should have values, and can have labels. In addition they can have other properties. You have only values.
The list is displayed under the text box. When you select something, the select function is triggered. The ui.item is the item from the json array received from the server. You can access its properties. Your item doesn't have an id. It has only a value. The response should display 'undefined'.
I think your link is wrong.
Firtzberg said:
Hello, I will try to help you.
First of all, you need to pass the correct link to the autocomplete function. In most browsers you can do RightClick->InspectElement anywhere. A window opens. There should be a tab "Network". By typing into the textbox, a request should be made and you will see where it goes. If there is no request, it probably means that you have errors in your javascript.
If the request is correct, you have to take care about the method, get or post.
The server should answer with a json formated array of items. The items should have values, and can have labels. In addition they can have other properties. You have only values.
The list is displayed under the text box. When you select something, the select function is triggered. The ui.item is the item from the json array received from the server. You can access its properties. Your item doesn't have an id. It has only a value. The response should display 'undefined'.
I think your link is wrong.
I'm aware of this. I normally transmitted getdata?term=mytext etc. Further it shows nothing.
I did as a 1:54 minute. so where the error then?
Do you get any response to getdata?term=mytext when you type it into the browser url?
I have a working autocomplete from jquery ui in the application I'm working on. I uses a function as source. Inside that function I make an ajax call.
Firtzberg said:
Do you get any response to getdata?term=mytext when you type it into the browser url?
I have a working autocomplete from jquery ui in the application I'm working on. I uses a function as source. Inside that function I make an ajax call.
The body is transmitted. image https://s019.radikal.ru/i642/1410/c3/b5301a5a7e5b.png
link through the browser is not transmitted. Throw off your revision please. There in a database?
Скин плз код или ссылку.
This works for me
Route::get('/help', function(){
return View::make('help');
});
Route::get('getdata',function(){
$term = Input::get('term');
$data = [
'R' => 'Red',
'O' => 'Orange',
'Y' => 'Yellow',
'G' => 'Green'
];
$result = [];
foreach($data as $color) {
if(strpos(Str::lower($color),$term) !== false) {
$result[] = ['value' => $color];
}
}
return Response::json($result);
});
The form
I changed only the script.
<script>
$('#auto').autocomplete({
source: 'getdata',
minLength: 1,
select:function(e,ui){
$('#response').val(ui.item.value);
}
});
</script>
hm. I do not work.
Route
Route::get('/help', function(){
return View::make('help');
});
Route::get('getdata',function(){
$term = Input::get('term');
$data = [
'R' => 'Red',
'O' => 'Orange',
'Y' => 'Yellow',
'G' => 'Green'
];
$result = [];
foreach($data as $color) {
if(strpos(Str::lower($color),$term) !== false) {
$result[] = ['value' => $color];
}
}
return Response::json($result);
});
View help.blade
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
</head>
<body>
<div class="container">
<h2>test</h2>
{{ Form::open(array('url' => '', 'files'=> true)) }}
<div class="form-group">
<label for="">Find a color</label>
<input type="text" class="form-control input-sm" name="auto" id="auto">
</div>
<div class="form-group">
<label for="">Response</label>
<input type="text" class="form-control input-sm" name="response" id="response" disabled>
</div>
{{Form::close()}}
<script>
$('#auto').autocomplete({
source: 'getdata',
minLength: 1,
select:function(e,ui){
$('#response').val(ui.item.value);
}
});
</script>
</body>
</html>
and where is the mistake? that can not head? try with my.
working code
$term = Input::get('term');
$data = [
'R' => 'Red',
'O' => 'Orange',
'Y' => 'Yellow',
'G' => 'Green'
];
$result = [];
foreach($data as $color) {
$result[] = ['value' => $color];
}
return Response::json($result);
why it does not work?
$term = Input::get('term');
$data = [
'R' => 'Red',
'O' => 'Orange',
'Y' => 'Yellow',
'G' => 'Green'
];
$result = [];
foreach($data as $color) {
if(strpos(Str::lower($color),$term) !== false) {
$result[] = ['value' => $color];
}
}
return Response::json($result);
Then you can be sure that your loop makes something wrong.
Try this
$term = Str::lower(Input::get('term'));
Hi, I don't know if is just me, but your code does not work when I put the first letter in uppercase.
Try this:
foreach($data as $color) {
//var_dump(stripos($color,$term)); //uncomment this lines and check
//var_dump(strpos(Str::lower($color),$term));
if(stripos($color,$term)!==false) {
$result[] = ['value' => $color];
}
}
Sorry for my poor English
follow my tutorial along with complete source code provided in the details section of the video: https://www.youtube.com/watch?v=jgpCb4yBtSw
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community