【发布时间】:2015-08-05 06:21:27
【问题描述】:
我正在使用 Angularjs 和 Laravel5。当我调用自动完成文本框时,服务调用没有响应。我的代码是......
userdefined.js
var app=angular.module('app',[]);
app.controller('ctrl',function($scope,$http){
$http.get("http://localhost:85/xamppserver/CODE_8JULY2015/public/front/state/w")
.success(function(response) {
$scope.availableTags = response;
});
$scope.complete=function(){
console.log($scope.availableTags);
$( "#tags" ).autocomplete({
source: $scope.availableTags
});
}
});
index.blade.php
<div class="form-group" ng-app="app" ng-controller="ctrl">
<label>State</label>
<input type="text" class="form-control" placeholder="State" id="tags" ng-keyup="complete()">
</div>
route.php
Route::get('state/{statename}', ['as' => 'customer','uses' => 'CustomerController@selectstate']);
CustomerController.php
public function selectstate($statename)
{
//$customer = new Customer();
//$result = $customer->where('client_state','like', '%'.$Filter.'%')->get(array('client_state'));
$state = new State();
$result = $state->where('state_name','like', '%'.$statename.'%')->get(array('state_name'));
header('Content-type: application/json');
echo json_encode($result);
}
如何使用angularjs调用服务?
【问题讨论】:
-
当您将该 URL 放入浏览器“localhost:85/xamppserver/CODE_8JULY2015/public/front/state/w”时,您会得到预期的响应吗?
-
是的,我收到了 json 格式的回复,例如 [{"state_name":"West Bengal"}]
-
JS 控制台有错误吗?请求是否已发送?你得到回应了吗?在成功处理程序中添加 console.log(response) 并粘贴结果