我想在提交后在评论框上写时显示评论我需要在评论框中显示我们写的内容(当我提交评论时它正在数据库上工作,它将保存到数据库我需要在评论框下显示该值然后我正在使用 ajax 将值发送到另一个页面)
索引.html
<html>
<body>
<head>
<script src="jquery-1.9.1.js"></script>
</head>
<div class="wrapper"style=" margin: 0 auto;width: 1000px;">
<div class="header"style="width:1000px;height:100px;background:#A6D1ED;"></div>
<div class="main"style="width:1000px;height:400px;background:#EEEAF2;">
<form name="form" method="post" action="insertcom.php">
<textarea name="comments" id="comments"style="width:500px;height:100px;"></textarea>
<input type="submit" name="Submit" value="Submit" id="btnS"/>
</form>
<div id="jcontent"></div>
<script type="text/javascript">
/* * Checking the Login - * */
$('#btnS').on('click',function(e){
e.preventDefault();
var data_get = {
'comments': $('#comments').val().trim(),
<!-- 'username' : $('#username').val().trim(), -->
<!-- 'password' : $('#password').val().trim(), -->
<!-- 'email' : $('#email').val().trim() -->
<!-- 'comments' : $('#comments').val().trim() -->
};
$.ajax({
url : 'insertcom.php',
type : 'POST',
data : data_get,
timeout : 30000,
success : function(response_data, text, xhrobject) {
console.log(text);
if(text == "success"){
$('#jcontent').html('success');
}
else if(text == "ERROR"){
$('#jcontent').html(' Fail ');
}
}
});
});
</script>
</div>
<div class="footer"style="width:1000px;height:100px;background:#7290A3;"></div>
</div>
<style>
h1{margin:0px;}
</style>
</body>
</html>
插入com.php
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="713481"; // Database name
$tbl_name="test_four"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$comments=$_POST['comments'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(comments)VALUES('$comments')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
请帮助我这是我的项目......