Ajax 调用不成功,但 firebug net 显示 Ok

Ajax call is not successfull but firebug net shows Ok

本文关键字:net 显示 Ok firebug 调用 不成功 Ajax      更新时间:2023-09-26

下面是我的代码。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 = "answerswer">
answer
</p>
<script>
$(document).ready(function(){
$("#foo").submit(function(event){
event.preventDefault();
// $("#newcommentblock").html(&#039;<img src="a.gif"/>&#039;);
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);
    });

任何帮助将不胜感激。 谢谢

好的,这是我的得到评论.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);

?>

检查返回的 html 中的语法。我遇到了类似的问题,并且标签中的格式不正确的属性使我的应用程序静默失败。