如何在.js.php文件中获得$ _GET变量?
问题描述:
所以我的主页上我有
<?php
require_once('config.inc.php');
require_once($rootdir . $dirsubfolder . 'navbar.php');
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=true"></script>
<script src="php/findme.php"></script>
<div class="hero hero-unit" style="padding: 0; padding-top: 3%;">
<div id="search" class='input-append'><input id="setNewDistance" class="span3" type="text" placeholder="Set Distance In Meters">
<button class='btn btn-info' id="changeDistance" type="submit">Search
</button></div>
<p class='alert-info' id="stopsfoundtext"></p>
<div id="gmaps"></div>
</div>
<?php
require_once($rootdir . $dirsubfolder . 'footer.php');
?>
然后在Findme.php我
<?php
/* Include neccesary files */
require_once('config.inc.php');
$gPlantSite = $_GET['plantsite'];
/* Connect to Database */
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_BASE);
/* Prepare Database statement */
if ($stmt = $mysqli -> prepare("SELECT route_id, Latitude, Longitude, Title, Weekday_Day, Weekend_Day, ADO_Day, Weekday_Night,
Weekend_Night, ADO_Night, Direction_Of_Bus,
What_Shift FROM Routes WHERE Plant_Site = ?")) {
/* Bind param to search for */
$stmt -> bind_param('s', $gPlantSite);
/* Execute and hope it works */
$stmt -> execute();
/* Bind the results to variables */
$stmt -> bind_result($gRoute_Id, $gLatitude, $gLongitude, $gTitle, $gWeekdayDay, $gWeekendDay, $ADODay,
$WeekdayNight, $WeekendNight, $ADONight, $gDirectionOfBus, $gwhatShift);
/* Leave connection open so that it may be queryd on the client side */
include "../js/findme.js.php";
}
?>
但它似乎仍然没有得到从PHP文件中的$ _GET,任何人有任何想法在这里用尽想法
我只是需要它得到$ _GET我尝试使用发布的想法作为答案,但似乎并没有为我工作。
答
你可以在你的js.php文件中包含这个文件。
,如果你这样做:
// .. other code ..
$stmt->bind_param('s', $gPlantSite); // at the bottom..
include "js.php"; // at the end of the file
,那么你也会有那么这个文件中获得$ _GET。
编辑
,只要你想,此刻它不会工作:
<script src="php/findme.php"></script>
,这意味着你要执行findme.php脚本,但你不提供任何查询字符串在这里,$ _GET将永远是空的。
提供任何通过$ _GET,你将需要提供对这样的脚本标签:
<script src="php/findme.php?plantsite=something"></script>
$ _GET [“plantsite”],然后将里面Findme值“东西”进行填充。 PHP。
由于您在Findme.php中包含findme.js.php文件,该脚本也将填充$ _GET。希望这有助于:)
我不明白这个问题。 js在哪里?以上都是PHP。 – mkaatman 2013-03-08 23:09:31
您是否尝试过使用Ajax? – kabuto178 2013-03-08 23:09:40
@mkaatman该文件是在我的.js.php文件中 – Datsik 2013-03-08 23:11:55