下面是我的代码。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);
?>