gpt4 book ai didi

php - Ajax /PHP : Returning values

转载 作者:行者123 更新时间:2023-11-30 00:46:50 24 4
gpt4 key购买 nike

问:我找不到我的代码不起作用的原因。

index.php

while($row = mysqli_fetch_array($result))
{

$Tri_CAPTION=$row['BOOKCAPTION'];
$Tri_IMAGE=$row['BOOKIMAGE'];
$BOOKT=$row['BOOKTITLE'];
$BOOKID=$row['BOOKID'];
$html = $Tri_IMAGE;
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$src = $xpath->evaluate("string(//img/@src)"); # "/images/image.jpg"


echo "<div class=\"mybooks\">
<a href=\"".$src."\" data-title=\"$BOOKT\" data-lightbox=\"example-3\" alt=\"Home\">
<img src=\"".$src."\" width=\"150\" height=\"150\"/>
</a>
<br />
Title:<strong>
".$BOOKT."</strong>
<br />

<a onClick=\"forusedata($BOOKID);\" href=\"#\">View Book</a>

</div>";
}
?>

Ajax :

<script>    
function forusedata(newid)
{

$.post('insert_home.php',{newid:newid}).done(function(data){
alert(data);

});
$('#Page1').dialog('open');
}

</script>

insert_home.php

else if(isset($_POST['newid']))
{
$newid = ($_POST['newid']);

$result = mysqli_query($con,"SELECT BOOKCAPTION FROM book WHERE BOOKID='$newid'");
while($row = mysqli_fetch_array($result)){
echo $row['BOOKCAPTION'];
}
mysqli_close($con);
}

最佳答案

为什么你的 insert_home.php 代码以 else if 开头?上面是不是少了什么东西?由于您没有说出实际上不起作用的内容,因此我猜测您没有收到任何警报数据。

我会将你的 insert_home.php 更改为:

if(isset($_POST['newid'])) {
$newid = ($_POST['newid']);
$result = mysqli_query($con,"SELECT BOOKCAPTION FROM book WHERE BOOKID='$newid'");
while($row = mysqli_fetch_array($result)){
echo $row['BOOKCAPTION'];
}
mysqli_close($con);
}
else {
echo ('no results');
}

这会让您知道问题是出在 ajax 还是出在 insert_home.php 页面。

关于php - Ajax /PHP : Returning values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21295529/

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