简体   繁体   中英

Passing value from HTML to external JS file and then to PHP file

I am creating a web app using different technologies.

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

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

filename.php piece of code:

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

Here you have the code for 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.

Any help is welcome.

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

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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