2011-11-02 54 views
0

這是我第一次使用jQuery,我不認爲它似乎工作。這裏是一些代碼...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

檢查螢火蟲/控制檯,看到任何錯誤..任何404? –

+0

檢查您的瀏覽器控制檯。你應該在那裏看到一個請求。在大多數瀏覽器中,它是'F12'鍵。 – PeeHaa

回答

0

您可以到您的通話添加一個回調函數來$.post

$.post(url, {comment: comment, assignment: assignment, pid: pid}, function(data, textStatus, jqXHR) { 
    alert(data); 
}); 

然後在你的PHP添加die('OK')您執行SQL語句之後。如果在運行insertComment時將OK置於警告框中,則您知道該調用已成功,並且您的PHP存在任何問題。

+0

謝謝,因爲這個我發現我非常簡單的錯誤 – willykao