[英]Passing value from HTML to external JS file and then to PHP file
我正在使用不同的技術創建一個Web應用程序。
首先,我打開一個HTML / PHP文件,例如http://....filename.php?id = 23
在此文件中,我正在調用一個外部JS文件,如下所示:
filename.php代碼段:
<script src="app/appClients.js"></script>
在這里,您有appClients.js的代碼:
var app = angular.module('myApp', ['ui.bootstrap']);
app.filter('startFrom', function() {
return function(input, start) {
if(input) {
start = +start; //parse to int
return input.slice(start);
}
return [];
}
});
app.controller('customersCrtl', function ($scope, $http, $timeout) {
$http.get('ajax/getClientsContacts.php').success(function(data){
$scope.list = data;
$scope.currentPage = 1; //current page
$scope.entryLimit = 5; //max no of items to display in a page
$scope.filteredItems = $scope.list.length; //Initially for no filter
$scope.totalItems = $scope.list.length;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.sort_by = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = !$scope.reverse;
};
});
並在線:
$http.get('ajax/getClientsContacts.php').success(function(data){
我需要將第一個URL的id參數傳遞給文件getClientsContacts.php,同時將其作為id參數傳遞給URL。
歡迎任何幫助。
感謝通過SRC屬性將vars傳遞給JavaScript,我已經解決了我的問題。
這是我在原始文件中所做的:
<script>
var idrecibida=(variable received from URL param)
</script>
<script src="app/appClients.js"></script>
然后我可以在需要的地方使用idrecibida。 簡單...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.