以下は私のコードです。Firebug は 200 OK ステータスを示します。
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<h1>
question: <br> myquestion33<br>
</h1>
<p id = "comments">
comments <br> <br> <br> <br> test<br> test<br>
</p>
Type your comment here
<div id = "newcommentblock">
<p id = "newComment"> </p>
<form id = "foo" name = "commentbox" action = "#" >
<input type = "text" id ="newComment" name = "newComment">
<input type = "submit" value = "post a comment">
</form>
</div>
<p id = "answer">
answer
</p>
<script>
$(document).ready(function(){
$("#foo").submit(function(event){
event.preventDefault();
// $("#newcommentblock").html('<img src="a.gif"/>');
request = $.ajax({
url: "getcomment.php",
type: "POST",
timeout:30000,
dataType: "text",
data:{getquestionid: 33
,
getcomment: "test" } ,
});
alert("inside script");
request.done(function (response, textStatus, jqXHR){
console.log("Hooray, it worked!");
//$("#comments").html(response);
});
request.fail(function (jqXHR, textStatus, errorThrown){
console.error(
"The following error occured: " +
textStatus, errorThrown
);
});
request.always(function () {
});
console.log("hi inside");
});
});
</script>
現在、バックエンドのデータベースが最新の値で更新されており、firebug も OK ステータスを示しているため、内部に入ることができません
request.done(function (response, textStatus, jqXHR){
console.log("Hooray, it worked!");
//$("#comments").html(response);
});
どんな助けでも大歓迎です。ありがとうございました
ここに私のgetcomment.phpがあります
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL :(");
$selected = mysql_select_db("place",$dbhandle)
or die("Could not select akshat :(");
$getcomment=$_POST["getcomment"];
$getquestionid=$_POST["getquestionid"];
$pkey=rand();
$result = mysql_query("INSERT INTO place_comment (sno,comment) VALUES ('$pkey','$getcomment') ")
or die(mysql_error());
$result1 = mysql_query("INSERT INTO question_comment (q_sno,c_sno) VALUES ('$getquestionid','$pkey') ")
or die(mysql_error());
//fetch tha data from the database
//while ($row = mysql_fetch_array($result)) {
// echo " ".$row{'question'}."<br>";
// echo "hello";
//}
//close the connection
mysql_close($dbhandle);
?>