使用Slim框架的AJAX帖子输出500(内部服务器错误) [英] AJAX post in using slim framework outputs 500 (Internal Server Error)

查看:112
本文介绍了使用Slim框架的AJAX帖子输出500(内部服务器错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在此问题上停留了好几天了,此处这是我以前的问题,但所有评论似乎都无效.我已经尝试了多种方法并设法摆脱了404错误,但是现在出现了500错误...

I have been stuck on this for days now, here is my previous question, but none of the comments seem to work. I have tried multiple things and managed to get rid of the 404 error, but now there is a 500 error...

  • 基本上,我想在事件发生时发布AJAX查询.
  • 使用AJAX查询解析值来运行Slim发布路线.
  • 使用Slim post路由并使用解析后的值从数据库中选择数据.
  • 然后从查询中返回结果并将其显示在选择框中.

如果有人知道如何解决这个问题,我将非常感激!!!

If anyone has any idea how to solve this I would be so grateful!!!

这是代码:

//Post the AJAX request
<script>
    $(document).ready(function() {
        $('select#add-module-stackid').change(function() {
            var val = document.getElementById("add-module-stackid");
            var val2 = val.options[val.selectedIndex].value;
            //alert(val2);
            $.ajax({ 
                url: '/admin-get-add-module',
                data:{stackid:val2},
                dataType:'json',
                type: 'POST',
                success: function(response) {
                    console.error(JSON.stringify(response));
                    alert(response);
                },
                error: function() {
                    console.error("error");
                    alert('Not working!');
                }
            });
        });
    });
</script>

这是Slim Post路线代码:

Here is the Slim Post Route code:

$app->post('/admin-get-add-module', function () use($app){
$req = $app->request();
$myStacks = filterStacks($app);
$app->view()->appendData(array('data' => $data, "stacks"=> $myStacks, "username" => getUsername($app)));
$sql = $link->prepare("select * from evironments where StackID=?");
$sql->bind_param("i", $stackid);
})->name('admin-get-add-module');

似乎没有路线

显示控制台错误的图像:

Image to show console error:

这是标题错误:

推荐答案

我摆脱了500互联网服务器错误.我没有通过链接进行解析.

I got rid of the 500 internet server error. I wasn't parsing through the link.

$app->post('/admin-get-add-module', function () use($app,$link){ <<<<<<<<LINK HERE
    $req = $app->request();
    $stackid = $_POST['stackid'];
    $myStacks = filterStacks($app);
    $app->view()->appendData(array("username" => getUsername($app)));
    $sql = $link->prepare("select * from evironments where StackID=?");
    error_log(var_export($sql,true));
    $sql->bind_param("i", $stackid);
})->name('admin-get-add-module');

尽管这里是sql/ajax问题的链接

It still doesn't work though here is a link to the sql / ajax problem

这篇关于使用Slim框架的AJAX帖子输出500(内部服务器错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆