gpt4 book ai didi

javascript - PHP 和 JavaScript

转载 作者:行者123 更新时间:2023-11-27 22:32:34 27 4
gpt4 key购买 nike

我知道这两个东西在不同的位置运行,但我想知道是否有办法在我的 java 脚本文件中包含一点 php我需要生成唯一的网址来链接到个人资料和新闻帖子。即/#/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>

我需要 js 文件中的 url 相同。我只是不太确定该怎么做?任何帮助表示赞赏。对其他解决方案持开放态度!

最佳答案

有很多方法可以解决这个问题

您可以简单地将 JS 文件扩展名更改为 .php,然后仅输出 Javascript 中的链接,因为您希望这可能会产生干扰您的 IDE 的意外副作用(因为它将假定为常规 php 文件)。或者,您可以将其命名为 .js.php 之类的名称以增加清晰度,但我不知道这是否可以解决大多数 IDE 的问题(这更利于您的理智)

还有很多其他选项,例如使用上述方法将链接输出到数组,然后在普通 JS 文件中迭代它们。如果采用这种方法,最好在两个文件中注释为什么要设置数据或从哪里获取数据以供将来引用。

关于javascript - PHP 和 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39422628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com