无法在PHP中加载资源500错误ajax POST

时间:2012-04-16 08:21:05

标签: php jquery ajax post

我见过很多其他这样的帖子,但我看不出有什么不对的。我也读过它可能是托管(Heroku)的问题所以我创建了一张票,但3天后没有答案。

以下是发送信息的代码:

(discuss.php)        

    <script type="text/javascript">
        $(function() {
            $('#ideasubmit').click(function() {
                console.log();
                $('#ideacontainer').append('<img src="images/loading.gif" alt="Please Wait" id="idealoading" />');

                var ideatitle = $('#ideatitle').val();
                var ideafbid = $('#ideafbid').val();
                var idea = $('#idea').val();

                $.ajax({
                    url: 'ajaxsqli.php',
                    type: 'POST',
                    data: 'ideatitle=' + ideatitle + '&ideafbid=' + ideafbid + '&idea=' + idea,

                    success: function(result) {
                        $('#idearesponse').remove();
                        $('#ideacontainer').append('<p id="idearesponse">' + result + '</p>');
                        $('#idealoading').fadeOut(500, function() {
                            $(this).remove();
                        });
                    }
                });
                return false;
            });
        });

下面是代码文件,它在发送信息时收到错误:

(ajaxsqli.php)

    $db = new db;

$query = "INSERT into comments(user_fbid, discuss_type, discuss_post_title, discuss_post, date) VALUES (?, ?, ?, ?, )";

$stmt = $db->stmt_init();
if($stmt->prepare($query)) {
    $stmt->bind_param('iissi', $_POST['ideafbid'], 1, $_POST['ideatitle'], $_POST['idea'], date('Ymd'));
    $stmt->execute();
}

if($stmt) {
echo "Thank you. We'll be in touch with you shortly!";
} else {
echo "There was a problem. Please  try again later.";
}

?>

奇怪的是我3天前工作了,我去改进了一些代码,现在我无法使其工作,即使我恢复了备份。

这是完整的错误消息:

无法加载资源:服务器响应状态为500(内部服务器错误)并指向ajaxsqli.php

使用Chrome Inspect Elements我可以看到POST正在发布信息,但没有回复信息。

这段代码有什么问题吗?

1 个答案:

答案 0 :(得分:1)

500错误通常是指php中的问题。使用参数在浏览器中加载ajaxsqli.php(将$_POST更改为$_REQUEST然后您可以使用查询字符串.EG

$db = new db;

$query = "INSERT into comments(user_fbid, discuss_type, discuss_post_title, discuss_post, date) VALUES (?, ?, ?, ?, )";

$stmt = $db->stmt_init();
if($stmt->prepare($query)) {
    $stmt->bind_param('iissi', $_REQUEST['ideafbid'], 1, $_REQUEST['ideatitle'], $_REQUEST['idea'], date('Ymd'));
    $stmt->execute();
}

if($stmt) {
echo "Thank you. We'll be in touch with you shortly!";
} else {
echo "There was a problem. Please  try again later.";
}

?>

然后转到http://yourhost/ajaxsqli.php?ideafbid=data&ideatitle=data&idea=data,看看PHP错误是什么