繁体   English   中英

将值从HTML传递到外部JS文件,然后传递给PHP文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM