JavaScript新功能。過去幾天我一直在學習很多東西。當我包含一個php腳本時,PHP/javascript腳本停止工作
我有一個加載日曆的腳本。日曆佈局是在PHP中構建的。我有以下代碼:
jQuery.get(PLUGIN_DIR+'/bookings/reservation.php', function(data)
{
jQuery('#content_div').html(data);
});
Reservation.php
<?php
echo '</div><div class="box_div" id="reservation_div"><div class="box_top_div" id="reservation_top_div"><div id="reservation_top_left_div"><a href="." id="previous_week_a">< Previous week</a></div><div id="reservation_top_center_div">Reservations for week <span id="week_number_span">' . global_week_number . '</span></div><div id="reservation_top_right_div"><a href="." id="next_week_a">Next week ></a></div></div><div class="box_body_div"><div id="reservation_table_div"></div></div></div><div id="reservation_details_div">';
?>
上述工作正常。但是,當我添加以下include來定義global_week_number時,它將停止工作。
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-content/plugins/bookings/js/header-js.php');
echo '</div><div class="box_div" id="reservation_div"><div class="box_top_div" id="reservation_top_div"><div id="reservation_top_left_div"><a href="." id="previous_week_a">< Previous week</a></div><div id="reservation_top_center_div">Reservations for week <span id="week_number_span">' . global_week_number . '</span></div><div id="reservation_top_right_div"><a href="." id="next_week_a">Next week ></a></div></div><div class="box_body_div"><div id="reservation_table_div"></div></div></div><div id="reservation_details_div">';
?>
包含文件頭,js.php:
<script type="text/javascript">
<?php
echo "PLUGIN_DIR = '".plugins_url()."';";
echo "global_css_animations = ".global_css_animations.";";
echo "global_week_number = ".global_week_number.";";
?>
</script>
我在這裏的損失。當我包含header-js.php時,我不知道爲什麼它停止工作。任何想法?
謝謝。
那麼PHP生成的JS如何呢?而且,你的變量是錯誤的,錯過'$'符號。 – djot
你在瀏覽器控制檯中有沒有明顯的錯誤(一般打到f12打開)? – scrappedcola
是'global_css_animations'和'global_week_number' PHP常量嗎?如果不是,那麼在引用它們作爲PHP變量時,它們需要以'$'作爲前綴。 (即'echo「global_week_number =」。$ global_week_number。「;」;') – Divey