gpt4 book ai didi

javascript - 如何以 Angular 使用functions.php文件中的函数

转载 作者:行者123 更新时间:2023-12-03 04:07:53 26 4
gpt4 key购买 nike

我想通过我的 Angular 中的 PHP 中的函数检索用户信息。

Angular 代码:

$scope.users = $http({
method: 'GET',
url: 'functions.php/getUsers()'
}).then(function(response){
$scope.users = response.data;
},function(reason){
$scope.error = reason.data;
});
}

其中 getUsers() 是将 json 数据返回到 Angular 的函数。

还有其他方法可以使用 PHP 文件中的 Angular 函数吗?

最佳答案

remember the functions can not be equal to our public variable, in this sample you have $scope.users as function and also you have that again equal to response.data (actually you miss the function)

you can't read from files, you have to use api URL which return json to you

$scope.users = $http({
method: 'GET',
url: 'functions.php/getUsers()'
}).then(function(response){
$scope.users = response.data;
},function(reason){
$scope.error = reason.data;
});
}

更改为

$scope.getUsers = function(){
//for example api url for your users is "http://localhost:8080/users"
var api = "you api url";
$http({method: 'GET', url: api}).then(function(response){
$scope.users = response.data;
},function(reason){
$scope.error = reason.data;
});
}
}
//request data
$scope.getUsers();

或者直接使用而不使用函数

//for example api url for your users is "http://localhost:8080/users"
var api = "you api url";
$http({method: 'GET', url: api}).then(function(response){
$scope.users = response.data;
},function(reason){
$scope.error = reason.data;
});
}

关于javascript - 如何以 Angular 使用functions.php文件中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44468831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com