使用AngularJS和PHP Web服务进行简单搜索
我曾尝试使用angularJS comunicate和php web服务创建简单搜索。请查看以下内容这是interface index.html: ` 然后控制器app.js:使用AngularJS和PHP Web服务进行简单搜索,php,angularjs,web-services,rest,Php,Angularjs,Web Services,Rest,我曾尝试使用angularJS comunicate和php web服务创建简单搜索。请查看以下内容这是interface index.html: ` 然后控制器app.js: `app.controller('grafikku', function ($scope, $rootScope, $location, $routeParams, services, cpu) { $scope.find= function(cpu) { $location.path('/grafik
`app.controller('grafikku', function ($scope, $rootScope, $location, $routeParams, services, cpu) {
$scope.find= function(cpu) {
$location.path('/grafik');
services.grafik5(cpu);
};`
在php方面:
private function grafik5()
{
if($this->get_request_method() != "GET")
{
$this->response('',406);
}
$cpu=(string)$this->_request['cpu'];
$sql = "Select * FROM data WHERE cpu ="$cpu";
$r = $this->mysqli->query($sql) or die($this->mysqli->error.__LINE__);
$success = array("status" => "Success", "msg" => "Successfully one record deleted.");
$this->response($this->json($success),200);
}
我已经用postman在php端进行了测试,测试结果正常。但我知道我的错误在角度上。我真的被困在这里了。请帮帮我,我是新来的
return $http.get(serviceBase + 'grafik5?cpu=' + cpu).then(function (status) {
return status.data;
});
$http.get是异步的,所以在这里我认为您最多只能返回一个承诺(请参阅)
您可以先尝试获取数据:
obj.grafik5= function (cpu) {
return $http.get(serviceBase + 'grafik5?cpu=' + cpu);
};
app.controller('grafikku', function ($scope, $rootScope, $location, $routeParams, services, cpu) {
$scope.find= function(cpu) {
services.grafik5(cpu).then(function(data){
console.log(data);
}), function (error){
console.log(error);
}
};
更新:您好,我忘记了一些东西,我在语法上有一个错误错误错误:这是一个意外的标识符:。当('/grafik',{title:'grafik',templateUrl:'grafik/grafik1.php'controller:'grafikku'})您在controllero之前缺少一个逗号噢,谢谢,回到最重要的问题,我已经尝试了app.controller('grafikku',函数($scope,$rootScope,$location,$routeParams,services,cpu){$scope.find=function(cpu){services.grafik5(cpu).then(function(data){console.log(data);}),function(error){console.log(error);};但控制台上没有显示任何内容。当我单击表单上的提交按钮时,没有发生任何情况。错误在哪里?之前谢谢可能问题在于$http语法、serviceBase值或其他问题。是的,我真的不知道问题在哪里,我为此浪费了6个小时。serviceBase与其他功能正常工作。
return $http.get(serviceBase + 'grafik5?cpu=' + cpu).then(function (status) {
return status.data;
});
obj.grafik5= function (cpu) {
return $http.get(serviceBase + 'grafik5?cpu=' + cpu);
};
app.controller('grafikku', function ($scope, $rootScope, $location, $routeParams, services, cpu) {
$scope.find= function(cpu) {
services.grafik5(cpu).then(function(data){
console.log(data);
}), function (error){
console.log(error);
}
};