Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax调用未成功,但firebug net显示Ok_Javascript_Ajax_Jquery - Fatal编程技术网

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

Javascript Ajax调用未成功,但firebug net显示Ok,javascript,ajax,jquery,Javascript,Ajax,Jquery,下面是我的代码。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

下面是我的代码。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(&#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>
任何帮助都将不胜感激。多谢各位

好的,这是我的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);


?>


检查返回的html中的语法。我遇到了类似的问题,标记中的一个错误属性导致我的应用程序自动失败。

请填写:“发生了以下错误:”@KevinB实际上它根本没有进入error函数…而且它也没有进入always函数…有点奇怪,因为如果它是一个错误,它至少应该给出error…任何suggestions@SarathSprakash与前面的评论一样,您应该在控制台的某个地方有一个错误。jquery ajax请求不会在没有输入失败回调的情况下自动失败。@user1590595它的工作不是客户端的问题这里是工作小提琴,您是否检查了控制台或服务器端可能存在其他问题,请发布您的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);


?>