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

时间:2023-01-26 14:20:04

I am creating a web app using different technologies.

我正在使用不同的技术创建一个Web应用程序。

First I am opening a HTML/PHP file like this http://....filename.php?id=23

首先,我打开一个HTML / PHP文件,如http://....filename.php?id = 23

At this file I am calling an external JS file, like this:

在这个文件中我调用外部JS文件,如下所示:

filename.php piece of code:

filename.php一段代码:

<script src="app/appClients.js"></script> 

Here you have the code for appClients.js:

这里有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;
    };
});

And at line:

在线:

 $http.get('ajax/getClientsContacts.php').success(function(data){

I need to pass the id parameter from the first URL to file getClientsContacts.php, also as id parameter to the URL.

我需要将id参数从第一个URL传递给文件getClientsContacts.php,也作为URL的id参数。

Any help is welcome.

欢迎任何帮助。

1 个解决方案

#1


0  

Thanks to Pass vars to JavaScript via the SRC attribute I have solved my issue.

感谢通过SRC属性将vars传递给JavaScript,我已经解决了我的问题。

This is what I have done at my original file:

这是我在原始文件中所做的:

<script>
var idrecibida=(variable received from URL param)
</script>
<script src="app/appClients.js"></script>

and then I can use idrecibida where needed. Simple...

然后我可以在需要的地方使用idrecibida。简单...

#1


0  

Thanks to Pass vars to JavaScript via the SRC attribute I have solved my issue.

感谢通过SRC属性将vars传递给JavaScript,我已经解决了我的问题。

This is what I have done at my original file:

这是我在原始文件中所做的:

<script>
var idrecibida=(variable received from URL param)
</script>
<script src="app/appClients.js"></script>

and then I can use idrecibida where needed. Simple...

然后我可以在需要的地方使用idrecibida。简单...