gpt4 book ai didi

javascript - PHP:AJAX 请求时出现 500 内部服务器错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:27 24 4
gpt4 key购买 nike

我有一个 bdd MySQL,它会定期更新人工智能生成的文本。我想将这个无限文本显示为网络发布,所以我们这样做了,作为一个粗略的测试:

<head>
<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<div id="myTable"></div>

<script type="text/javascript">
function page_refresh() {
$.ajax({
url: 'getData.php',
type: 'GET',
success: function(data) {
$('#myTable').html(data);
},
error: function(request,error) {
alert("Request error: " + JSON.stringify(request));
}
});
}

var period = 10000; // NOTE: period is passed in milliseconds
setInterval(page_refresh, period);
</script>
</body>

正在调用 getData.php

<?php

$dbhandle = new PDO("mysql:host='localhost';dbname='writing'", "root", "*********"); //this connects to your mysql table
$sql = "SELECT text, id, date FROM table_02 ;"; //this is your query, where you select what data you want from the table
$query = $dbhandle->prepare($sql);

if ($query->execute() == FALSE) {
die("Query error: " . implode($query->errorInfo(), ' '));
} //this is a measure to close the connection if there is an error

echo('<table>');
echo('<tr><th>id</th><th>date</th><th>text</th></tr>');

while ($row = $query->fetch()) {
echo('<tr>');
echo('<td>').$row ['id'].'</td>');
echo('<td>').$row ['date'].'</td>');
echo('<td>').$row ['text'].'</td>');
echo('</tr>');
}

echo('</table>');

我们遇到了两个问题。首先,我们只得到一个空白页。其次,一两秒后,我们收到此错误消息:

{Request error : "readyState":4,"responseText":"","status":500,"statusText":"Internal Server Error"}

有什么想法吗?

我的错误日志

> [Thu Jun 22 06:25:01.645901 2017] [mpm_prefork:notice] [pid 17562]
> AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal
> operations [Thu Jun 22 06:25:01.645918 2017] [core:notice] [pid 17562]
> AH00094: Command line: '/usr/sbin/apache2' [Thu Jun 22 08:12:32.453382
> 2017] [:error] [pid 19559] [client 77.198.111.62:57256] PHP Parse
> error: syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 14, referer:
> http://82.223.18.239/testTom.php [Thu Jun 22 08:21:09.579406 2017]
> [:error] [pid 19560] [client 77.198.111.62:57430] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 14, referer:
> http://82.223.18.239/testTom.php [Thu Jun 22 08:21:09.582093 2017]
> [:error] [pid 19648] [client 77.198.111.62:57431] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 14, referer:
> http://82.223.18.239/testTom.php [Thu Jun 22 09:09:04.947344 2017]
> [:error] [pid 19559] [client 77.198.111.62:59193] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 14, referer:
> http://82.223.18.239/testTom.php [Thu Jun 22 09:09:11.454622 2017]
> [:error] [pid 19648] [client 77.198.111.62:59196] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 14 [Thu Jun 22 09:10:28.529637 2017]
> [:error] [pid 19561] [client 77.198.111.62:59227] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 14 [Thu Jun 22 09:10:32.709239 2017]
> [:error] [pid 19558] [client 77.198.111.62:59229] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 14 [Thu Jun 22 09:11:39.122539 2017]
> [:error] [pid 19559] [client 77.198.111.62:59270] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 13, referer:
> http://82.223.18.239/testTom.php [Thu Jun 22 09:11:51.476161 2017]
> [:error] [pid 19648] [client 77.198.111.62:59285] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 13, referer:
> http://82.223.18.239/testTom.php [Thu Jun 22 09:14:14.697094 2017]
> [:error] [pid 19557] [client 77.198.111.62:59440] PHP Parse error:
> syntax error, unexpected ')', expecting ',' or ';' in
> /var/www/html/getData.php on line 13, referer:
> http://82.223.18.239/testTom.php

按照您的建议,我现在有了:

<!DOCTYPE html>
<head>

<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

</head>

<body>
<div id="myTable"></div>

<script type="text/javascript">
function page_refresh() {
$.ajax({
url : 'getData.php',
type : 'GET',
success : function(data) {
$('#myTable').html(data);
},
error : function(request,error)
{
alert("Request error : "+JSON.stringify(request));
}
});
}

var period = 10000; //NOTE: period is passed in milliseconds
setInterval(page_refresh, period);
</script>

</body>

至于 getData.php :

<?php
$dbhandle = new PDO("mysql:host=localhost;dbname=writing", "root", "*********");//this connects to your mysql table
$sql = "SELECT text, id, date FROM table_02 ;"; //thise is your query, where you select what data you want from the table
$query = $dbhandle->prepare($sql);

if ($query->execute() == FALSE)
{ die("Query error: " . implode($query->errorInfo(), ' ')); } //this is a measure to close the connection if there is an error

echo('<table>');
echo('<tr><th>le nom de la rose</th></tr>');
while ($row = $query->fetch()) {
echo('<tr>');
##echo('<td>'.$row ['id'].'</td>');
##echo('<td>'.$row ['date'].'</td>');
echo('<td>'.$row ['text'].'</td>');
echo('</tr>');
}
echo('</table>');
?>

它的工作!使用此代码,页面每 X 秒刷新一次,但似乎一点也不流畅。如果我将它设置为每 100 毫秒刷新一次,它就会像使用 F5 一样工作和断断续续。你知道如何解决吗?如何设置平滑刷新?这里有更有趣的使用 ajax 的方法吗?

最佳答案

您的连接不应包含...

$dbhandle = new PDO("mysql:host='localhost';dbname='writing'", "root", "*********");  //this connects to your mysql table

应该是……

$dbhandle = new PDO("mysql:host=localhost;dbname=writing", "root", "*********");  //this connects to your mysql table

关于javascript - PHP:AJAX 请求时出现 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44693965/

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