2015-10-15 124 views
0

我正在使用不同的技術創建Web應用程序。將HTML值傳遞給外部JS文件,然後傳遞給PHP文件

首先我打開一個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。

任何幫助,歡迎。

+0

@arunpjohny,謝謝,但你標記的問題有任何接受的答案。 – mvasco

+0

這可能是因爲OP可能沒有興趣...但是有一個非常高的答案 –

+0

@arunpjohny,你是對的,但我不能看到如何將這個答案應用於我的代碼,如果你不能幫助我,我會盡力找到一個解決方案,但我想這是一個有趣的問題,可以幫助其他人。 – mvasco

回答

0

感謝Pass vars to JavaScript via the SRC attribute我已經解決了我的問題。

這是我在原來的文件已經完成:

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

,然後我可以使用idrecibida需要的地方。簡單...