PHP and JavaScript
PHP and JavaScript
我知道这两件事在不同的位置操作,我想知道是否有任何方式在我的java脚本文件中包含一点php我需要生成唯一的url链接到个人资料和新闻帖子。即/#/news/IDHERE和/#/profile/IDHERE下面我已经包含了脚本,构建我的导航为我
// create the module and name it scotchApp
var scotchApp = angular.module('RoutingApp', ['ngRoute']);
// configure our routes
scotchApp.config(function($routeProvider) {
$routeProvider
//Routes for HH TAB!!!
// route for the home page
.when('/', {
templateUrl: 'staff/staff/_frontend/news.php',
controller: 'mainController'
})
// route for the about page
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
// route for the team page
.when('/team', {
templateUrl: 'pages/test/test.html',
controller: 'teamController'
})
// route for the Job page
.when('/job', {
templateUrl: 'pages/test/test1.html',
controller: 'jobController'
})
// route for the FAQ page
.when('/faq', {
templateUrl: 'pages/test/test2.html',
controller: 'faqController'
})
// route for the Complaint page
.when('/complaint', {
templateUrl: 'pages/test/index.php',
controller: 'complaintController'
})
//Routes for Radio Player
// route for the request page
.when('/request', {
templateUrl: 'pages/requestline.php',
controller: 'requestsController'
})
// route for the Register page
.when('/register', {
templateUrl: 'pages/register.php',
controller: 'registerController'
})
});
//comtrollers for HH TAB
// home
scotchApp.controller('mainController', function($scope) {
$scope.HomeMessage = 'Home Controller Called !!!';
});
//About
scotchApp.controller('aboutController', function($scope) {
$scope.AboutMessage = 'About Controller Called !!!';
});
// team
scotchApp.controller('teamController', function($scope) {
$scope.teamMessage = 'team Controller Called !!!';
});
//jobs
scotchApp.controller('jobController', function($scope) {
$scope.jobMessage = 'Jobs Controller Called !!!';
});
//faq
scotchApp.controller('faqController', function($scope) {
$scope.faqMessage = 'FAQ Controller Called !!!';
});
//complaint
scotchApp.controller('complaintController', function($scope) {
$scope.complaintMessage = 'Complaint Controller Called !!!';
});
//controllers for radio player!!
//requests
scotchApp.controller('requestsController', function($scope) {
$scope.requestsMessage = 'Requests Controller Called !!!';
});
//register
scotchApp.controller('registerController', function($scope) {
$scope.registerMessage = 'Register Controller Called !!!';
});
假设我有一个运行查询的文件,这里是我的一个页面的例子!
$query = $db->query( "SELECT * FROM `news` WHERE `category` = '13' AND `status` = '1' ORDER BY `news`.`id` DESC" );
$array = $db->assoc( $query );
while( $array = $db->assoc( $query ) ) {
$time = date( "d/m/y ", $array['stamp'] );
$query99 = $db->query( "SELECT habbo FROM users WHERE id = '{$array['author']}'" );
$array99 = $db->assoc( $query99 );
$cquery = $db->query( "SELECT * FROM news_comments WHERE article = '{$array['id']}'" );
$comment = $db->num( $cquery );
?>
<a href="#/news/<?php echo $array['id"];?>></a>
我需要的url是相同的在js文件。我只是不太确定该怎么做。任何帮助都是感激的。对其他解决方案的想法持开放态度!
有很多方法可以做到
您可以简单地将JS文件扩展名更改为.php,然后按照您的希望在Javascript中输出链接,这可能会产生意想不到的副作用,扰乱您的IDE(因为它将假设一个常规的php文件)。或者,你也可以将其命名为。js.php这样更清晰一些,但我不知道这是否能解决大多数ide的问题(这更有利于你的理智)
还有很多其他的选择,比如使用上面的方法将链接输出到一个数组,然后在你的普通JS文件中遍历它们。如果采用这种方法,最好在两个文件中注释为什么要设置数据或从哪里获取数据,以便将来参考。
相关文章:
- JavaScript and LiveView (TIBCO Live Datamart)
- Javascript and onMouseOver
- javascript and css firefox issue
- geolocation with javascript and ruby on rails
- Javascript and the DOM issues
- Javascript and Java Communication
- Javascript and Knockout
- Javascript and Css: Height does not change
- javascript and Internet Explorer 8
- Javascript and html, UI construction
- Javascript and Lightbox
- javascript and css styling
- JavaScript and URL parameters
- Javascript and singleton pattern
- Javascript and Ajax Calls
- OAuth, javascript and many URI's
- Javascript and AJAX post method
- javascript and web services WSDL
- javascript and webview in android
- Javascript & and | symbols