这是我第一次使用jquery,我认为它似乎没有用。这是一些代码...
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type = "text/javascript">
function insertComment(comment, assignment, pid){
alert(comment);
alert(assignment);
alert(pid);
var url = "addComment.php";
$.post(url, {comment: comment, assignment: assignment, pid: pid});
}
</script>
继承人addComment.php
<?php
include ("viewComments.php");
//Connection string to get to database
$host = 'host';
$user = 'user';
$password = 'pw';
$dbh = new mysqli($localhost, $user, $password, "kao17_CS242Portfolio");
//Prpared statement for user inpur, prevent sql-injection attacks
$stmt = $dbh->prepare("INSERT INTO tbl_Comment (comment, project_title, parent_comment_id) VALUES (? , ? , ?)");
$stmt->bind_param('ssi', $prevComment, $prevAssignment, $parentID);
$prevAssignment = $_POST['assignment'];
$parentID = $_POST['pid'];
$prevComment = profanityCheck($_POST['comment']);
$stmt->execute();
?>
它没有做任何事情。如果真的去了addComments,它是否会提醒?或者我只是使用错误的帖子(SQL应该是正确的)。我知道我正在获取参数的信息(警报)任何帮助都会很棒,谢谢!
答案 0 :(得分:0)
您可以在调用$.post
:
$.post(url, {comment: comment, assignment: assignment, pid: pid}, function(data, textStatus, jqXHR) {
alert(data);
});
然后在PHP中执行SQL语句后添加die('OK')
。如果在运行OK
时在警告框中显示insertComment
,那么您知道调用已成功,并且您的PHP存在任何问题。