I am still looking forward to getting this solved. The simple thing to be done is to use autocomplete in an input form control, to my surprise it not puling the records from into the text input. If I query the result through the browser, I do see the results thus:
http://localhost:2222/json/redirects/
I do see this result:
[{"id":null,"value":"Andorra"},{"id":null,"value":"United Arab Emirates"},{"id":null,"value":"Afghanistan"},{"id":null,"value":"Antigua and Barbuda"},{"id":null,"value":"Anguilla"},{"id":null,"value":"Albania"},{"id":null,"value":"Armenia"},{"id":null,"value":"Netherlands Antilles"},{"id":null,"value":"Angola"},{"id":null,"value":"Antarctica"},
This is the blade file:
<!DOCTYPE html>
<html>
<head>
{!! Html::style('bootstrap/css/bootstrap.css') !!}
{!! Html::style('bootstrap/css/bootstrap.min.css') !!}
<link href="http://ift.tt/1BwSRK7" media="all" rel="stylesheet" type="text/css" />
<script src="http://ift.tt/1dLCJcb"></script>
<script src="http://ift.tt/1NKbGQl"></script>
</head>
<body>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<section class="panel panel-default">
<header class="panel-heading">
<input type="text" name="searchname" id="searchname" class="form-control" placeholder="enter name">
</header>
<div class="panel-body">
<table>
<tr>
<td><input type="text" name="id" id="id" class="form-control" placeholder="ID" ></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td><input type="text" name="name" id="name" class="form-control" placeholder="Name" ></td>
</tr>
</table>
</div>
</section>
</div>
</div>
</body>
<script type="text/javascript">
$('#searchname').autocomplete({
source: '{!! Url::route('jsonRedirect') !!}',
minlength: 1,
autofocus: true,
select: function(e, ui){
alert(ui);
}
});
</script>
</html>
This is the controller:
public function SelectLocationPlaces(Request $userAdressRequest)
{
$term = $userAdressRequest->term;
$data = Country::where('name', 'LIKE', '%'.$term.'%')->take(10)->get();
$results = array();
foreach ($data as $key => $value) {
$results[] = ['id'=>$value->id, 'value'=>$value->name];
}
return response()->json($results);
}
This is the route:
Route::get('json/redirects', array('as'=>'jsonRedirect', 'uses'=>'UserAddressController@SelectLocationPlaces'));
Error log:
<body>
<div id="sf-resetcontent" class="sf-reset">
<h1>Whoops, looks like something went wrong.</h1>
<h2 class="block_exception clear_fix">
<span class="exception_counter">1/1</span>
<span class="exception_title"><abbr title="Symfony\Component\Debug\Exception\FatalErrorException">FatalErrorException</abbr> in <a title="C:\Users\ken4ward\Documents\xampp\htdocs\tradersmart\storage\framework\views\d12352064f8db7567c7110c110aa0321 line 39" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">d12352064f8db7567c7110c110aa0321 line 39</a>:</span>
<span class="exception_message">Class 'Url' not found</span>
</h2>
<div class="block">
<ol class="traces list_exception">
<li> in <a title="C:\Users\ken4ward\Documents\xampp\htdocs\tradersmart\storage\framework\views\d12352064f8db7567c7110c110aa0321 line 39" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">d12352064f8db7567c7110c110aa0321 line 39</a></li>
</ol>
</div>
Please,kind hearts, what could be the reason why the autocomplete not working but yet I can view the json response on the url?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire