我正在尝试将 Div 的可编辑内容存储在 SQL 数据库中。但是,据我所知,isset($_POST["des"])
永远不会返回 true。
(我没有做太多的网站编码,所以我可能遗漏了一些非常基本/微不足道的东西)
概览页面.php:
<?php session_start();
include_once("php_includes/check_login_status.php");
?>
<?php
if(isset($_POST["des"]))
{
echo "Inside IF statement";
include_once("php_includes/db_conx.php");
$des = mysqli_real_escape_string($db_conx, $_POST['des']);
$sql = "UPDATE users SET project_description='$des' WHERE username='$log_username'";
}
?>
<!DOCTYPE html>
<html>
<head>
<script src="js/main.js"></script> <!--Points to external java script file-->
<script src="js/ajax.js"></script> <!--Points to external java script file-->
<script type="text/javascript">
function save_description()
{
var des = _("project_description").value;
var ajax = ajaxObj("POST", "overview_page.php");
//ajax.onreadystatechange = function() sorry this one shouldn't be here
ajax.send("des="+des);
}
</script>
</head>
<body>
<?php include_once("template_pagetop.php"); ?>
<div id="pageMiddle">
<div id="left_window">
<div id="project_description" name="project_description" contentEditable="true">
Please enter project description...
</div>
<center>
<button id="save" onclick="save_description()">Save</button>
</center>
</div>
</div>
</body>
</html>
和外部脚本:
ajax.js:
function ajaxObj( meth, url ) {
var x = new XMLHttpRequest();
x.open( meth, url, true );
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return x;
}
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}}
主.js:
function _(x)
{
return document.getElementById(x);
}