使用AJAX(JavaScript)加载页面&;PHP
我是Ryan,我被困住了。。。我想构建一个管理页面,您可以在其中切换页面,而无需加载同步(使用AJAX)。。。但这不是问题所在,问题在于我使用JavaScript(jQuery)调整元素大小,然后使用JavaScript(AJAX)加载一个php脚本异步。。。php脚本也有实现JavaScript(主要是jQuery)的不同元素。。。所以JavaScript工作,然后php工作,但在JavaScript拒绝工作之后!我怎样才能使这个正确 这就是它的样子: index.php:使用AJAX(JavaScript)加载页面&;PHP,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我是Ryan,我被困住了。。。我想构建一个管理页面,您可以在其中切换页面,而无需加载同步(使用AJAX)。。。但这不是问题所在,问题在于我使用JavaScript(jQuery)调整元素大小,然后使用JavaScript(AJAX)加载一个php脚本异步。。。php脚本也有实现JavaScript(主要是jQuery)的不同元素。。。所以JavaScript工作,然后php工作,但在JavaScript拒绝工作之后!我怎样才能使这个正确 这就是它的样子: index.php: <?php
<?php
session_start ();
require ('php/content.php');
if (!isset($_SESSION["admin"])) {
$_SESSION["admin"] = false;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Administratiepagina van Polen</title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<?php if ($_SESSION["admin"]) {
echo '<script type="text/javascript" src="JavaScript/page.js"></script>';
echo '<script type="text/javascript" src="stylesheets/admin_style.js"></script>';
} else {
echo '<script type="text/javascript" src="stylesheets/login_style.js"></script>';
} ?>
</head>
<body id="body" >
<?php load_page (); ?>
</body>
</html>
样式表->admin\u style.js:
$(document).ready(function () {
$(body).css('background', 'white');
$(".total-frame").css('height', ($(window).height() - $(".header").height() - 10) + 'px');
$(".mainframe").css('width', ($(window).width() - $(".list-menu").width() - 20 ) + 'px');
$(".mainframe").css('height', ($(".total-frame").height() - 10 ) + 'px');
$(".frame-content").css('height', ($(".total-frame").height() - $(".frame-header").height() - 20 ) + 'px');
});
$(window).resize(function () {
$(".total-frame").css('height', ($(window).height() - $(".header").height() - 10) + 'px');
$(".mainframe").css('width', ($(window).width() - $(".list-menu").width() - 20 ) + 'px');
$(".mainframe").css('height', ($(".total-frame").height() - 10 ) + 'px');
$(".frame-content").css('height', ($(".total-frame").height() - $(".frame-header").height() - 20 ) + 'px');
});
这是一场彻底的灾难!请帮帮我!已经,谢谢大家的关注 对于抽象问题,这是因为代码太多。您需要隔离特定的问题,并提供仅与该问题相关的相关代码。没有人能帮助你其他方面的话像
javascript拒绝工作
都是毫无意义的问题陈述你说这样的话是什么意思?请您再解释一下,好吗?关键是您需要向我们解释哪些特定行为没有按照您预期的方式进行,以及出现了哪些错误我希望在php完成后加载JavaScript,但我如何才能做到这一点?还是有更好的方法让网站更具响应性?
<?php
if (isset($_POST["login"])) {
login ();
}
function login () {
// ontvangen variabelen
$_username = $_POST["username"];
$_password = $_POST["password"];
// benodigde variabelen van de database
$_server = "something.host.com";
$_user = "user";
$_pass = "pass";
$_database = "database";
// connectie maken met de database
$_connection = mysqli_connect($_server, $_user, $_pass, $_database);
// de input velden escapen
$_username = mysqli_real_escape_string($_connection, $_username);
$_password = mysqli_real_escape_string($_connection, $_password);
unset ($_SESSION["error"]);
// controle: waardes zijn niet gelijk aan NULL
if (!isset($_username) || !isset($_password)) {
Error ("Alle velden zijn verplicht!");
} else {
// controle: voldoen de ingevulde waarden aan de eisen
$_pattern = "/^[A-Za-z0-9!@#%&*]{6,20}$/";
if (!preg_match($_pattern, $_username) || !preg_match($_pattern, $_password)) {
Error ("Vul reële waarden in!");
} else {
// controle: verbinding met de database
if (!$_connection) {
Error ("Geen verbinding!");
} else {
// verbinden met de database
$_sql = "SELECT * FROM users WHERE username = '$_username' AND password = MD5('$_password') AND admin = 1 ";
$_result = mysqli_query($_connection, $_sql);
// controle: feedback is van de database
if (!$_result) {
Error ("Geen feedback van de database!");
} else {
// controle: bestaan van het account
if(mysqli_num_rows($_result) != 1) {
Error ("Dit account bestaat niet!");
} else {
$_SESSION["admin"] = true;
header('location: http://admin.vanpolencv.nl');
return;
}
}
}
}
}
}
function Error ($_message) {
$_SESSION["error"] = $_message;
return;
}
?>
<?php
if (isset($_POST["logout"])) {
logout ();
}
function logout () {
// benodigde variabelen van de database
$_server = "something.host.com";
$_user = "user";
$_pass = "pass";
$_database = "database";
// connectie maken met de database
$_connection = mysqli_connect($_server, $_user, $_pass, $_database);
unset ($_SESSION["error"]);
session_destroy ();
header('location: http://admin.vanpolencv.nl');
return;
}
function Error ($_message) {
$_SESSION["error"] = $_message;
return;
}
?>
<?php
if (!isset($_REQUEST["p"])) {
error ();
} else {
load_content ($_REQUEST["p"]);
}
function load_content ($_name) {
switch ($_name) {
case "home":
echo "";
echo "";
echo "";
echo "";
break;
case "agenda":
echo "";
echo "";
echo "";
echo "";
break;
case "klanten":
echo "";
echo "";
echo "";
echo "";
break;
case "personeel":
echo "<h1>HALLO</h1>";
echo "";
echo "";
echo "";
break;
case "website":
// benodigde variabelen van de database
$_server = "something.host.com";
$_user = "user";
$_pass = "pass";
$_database = "database";
// connectie maken met de database
$_connection = mysqli_connect($_server, $_user, $_pass, $_database);
echo "<div class='web_builder'>";
$_sql = "SELECT titel, tekst FROM " . $_name . " ORDER BY ID ";
$_result = mysqli_query($_connection, $_sql);
while ($_row = mysqli_fetch_assoc($_result)) {
echo "<article class='web_builder_content' draggable='true'>";
echo "<input type='text' value='" . $_row['titel'] . "' />";
echo "<textarea>" . $_row['tekst'] . "</textarea>";
echo "</article>";
}
echo "</div>";
break;
case "documenten":
echo "";
echo "";
echo "";
echo "";
break;
case "instellingen":
echo "";
echo "";
echo "";
echo "";
break;
default:
echo "<h1>Deze pagina kon niet gevonden worden</h1>";
}
}
function error () {
}
?>
function page (page_name) {
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
document.getElementById("frame-content").innerHTML = request.responseText;
}
}
request.open("GET", "php/page.php?p=" + page_name, true);
request.send();
}
$(document).ready(function () {
$(body).css('background', 'white');
$(".total-frame").css('height', ($(window).height() - $(".header").height() - 10) + 'px');
$(".mainframe").css('width', ($(window).width() - $(".list-menu").width() - 20 ) + 'px');
$(".mainframe").css('height', ($(".total-frame").height() - 10 ) + 'px');
$(".frame-content").css('height', ($(".total-frame").height() - $(".frame-header").height() - 20 ) + 'px');
});
$(window).resize(function () {
$(".total-frame").css('height', ($(window).height() - $(".header").height() - 10) + 'px');
$(".mainframe").css('width', ($(window).width() - $(".list-menu").width() - 20 ) + 'px');
$(".mainframe").css('height', ($(".total-frame").height() - 10 ) + 'px');
$(".frame-content").css('height', ($(".total-frame").height() - $(".frame-header").height() - 20 ) + 'px');
});