gpt4 book ai didi

php - jquery 未将值添加到数据库,readystate=0 和 status=0

转载 作者:行者123 更新时间:2023-11-29 14:31:05 24 4
gpt4 key购买 nike

我的脚本似乎不起作用。每次我尝试使用该表单时,我都会收到readystate = 0和status = 0的错误。任何帮助将不胜感激。我有以下表格:

<form action="" method="post" >

<input type="text" name="name" id="tekst"/><br/>
<input type="text" name="name" id="autor"/><br/>
<input type="submit" name="<?php echo $id; ?>" value="Send" id="submit"/>

</form>
<div class="response"></div>

然后通过以下代码处理输入字段中的值:

$("input#submit").click(function(){  
var id = $("input#submit").attr("name");
var autor = $('input#autor').val();
var tresc = $('input#tekst').val();


$.ajax({
type: "POST",
url: "add_comment.php",
data:
{id: id,
autor: autor,
tresc: tresc},
success: function(data){
$(".response").text(data);
},
error:function(xhr,err){
alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
alert("responseText: "+xhr.responseText);

}



});
});

这是我的 add_comment.php:

<?php
$id = $_POST['id'];
$autor= $_POST['autor'];
$tresc = $_POST['tresc'];

if(isset($id) && isset($autor) && isset($tresc)){
include("db/connection.php");

$zapytanie= "INSERT INTO komentarze(id_ref, autor, tresc) values ('$id', '$autor', '$tresc')";
$wynik = $db->query($zapytanie);
echo "Added";
}else{
echo "Problem";
}


?>

编辑:id_ref 不是 auto_increment 字段。该脚本在本地主机上运行

最佳答案

首先,您的表单不正确...name="name", class=".response"??

<form action="" method="post" >
<input type="text" name="tekst" id="tekst"/><br/>
<input type="text" name="autor" id="autor"/><br/>
<input type="submit" name="id" value="Send" id="submit"/>
</form>
<div class="response"></div>

您的 PHP 文件应该是“

<?php
$id = $_POST['id'];
$autor= $_POST['autor'];
$tresc = $_POST['tekst'];

if(isset($id) && isset($autor) && isset($tresc)){
include("db/connection.php");

$zapytanie= "INSERT INTO komentarze(id_ref, autor, tresc) values ('$id', '$autor', '$tresc')";
$wynik = $db->query($zapytanie);
echo "Added";
}else{
echo "Problem";
}
?>

关于php - jquery 未将值添加到数据库,readystate=0 和 status=0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10027718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com