【问题标题】:Laravel AJAX 500 Internal Error with no messageLaravel AJAX 500 内部错误,没有消息
【发布时间】:2020-03-20 13:08:52
【问题描述】:

我已经建立了一个计算复数的报告,并且我使用了 ajax。 该代码在我的本地主机上完美运行,但在服务器上它抛出 500 内部错误而没有消息。我尝试在每个代码块之后使用dd,这就是它引发错误的部分

$decoded_needs = [];
  foreach ($needs_teacher as $needs) {
    $decoded_needs[] = json_decode($needs->training_needed);
  }
  if (empty($decoded_needs)) {
    $training_needs_teacher = array(['0' => 'None']);
  } else {
    $sanitized_needs = [];
    foreach ($decoded_needs as $key => $items) {
      foreach ($items as $index => $item) {
        foreach ($item as $name => $bit) {
          $sanitized_needs[$name][] = $bit;
        }
      }
    }

$s_standards = [];
$s_sub_category = [];

// dd() works here

foreach ($sanitized_needs['standard'] as $skey => $standard) {
  $sname = DB::table('lesson_observation_teacher_standards')->where('id', $standard)->first()->name;
  $s_standards[] = $sname;
    foreach ($sanitized_needs['sub_category'] as $key => $substandard) {
      $name = DB::table('lesson_observation_teacher_standard_categories')->where('id', $substandard)->first()->name;
       if ($key == $skey) {
         $s_sub_category[$sname][] = $name;
       }
    }
}
// but not here 
$training_needs_teacher = [];
foreach ($s_sub_category as $key => $index) {
  foreach ($index as $items) {
    $training_needs_teacher[$key] = array_count_values($index);
  }
}

$sanitized_needs = [];
foreach ($training_needs_teacher as $key => $items) {
  foreach ($items as $index => $item) {
    $sanitized_needs[$key . ":" . count($items)][] = $index . ":" . $item;
  }
}
$training_needs_teacher = $sanitized_needs;
}

我知道我可以在很多情况下使用WhereIn,但我需要重复的项目。我只想知道有没有办法解决这个问题? 请注意,我的 ajax 包含 csrf 令牌。

【问题讨论】:

  • 很可能你的本地主机有额外的 PHP 扩展,这些扩展不在你的服务器上 - 创建一个 php 文件,在服务器和本地机器上都放 <?php php_info(); ?> 并比较差异。 - 如果您有 root 访问权限,请尝试运行 apt-get install php-common 或 (CentOS) yum install php-common
  • @JackWright 谢谢我试试
  • @Areg 请使用选择方法选择name。请参阅下面的答案。
  • storage/logs/laravel.log 中通常有一个条目可以提示问题所在

标签: php ajax laravel server


【解决方案1】:

我认为问题在于 DB 的路径

我遇到过这个问题,您必须在本地环境中对路径进行三次检查,可能您的站点位于根路径中,因此 DB:: 工作正常,但在生产中您应该在 DB 引用之前放置一些内容,例如 \rootFolder\数据库::

希望对你有帮助。

【讨论】:

  • 设置正确并且在APP_ENV=production
  • 请尝试将 DB:: 替换为 \DB:: 并让我们知道结果是否有变化。
  • @Areg 正如您在本地主机中所说的,工作正常。这是错误的!如果不使用 \DB:: OR use DB; MAKE SURE..,这也无法在 localhost 中工作
  • @AmitSenjaliya 你需要先冷静一下。其次,它确实在本地主机上工作
猜你喜欢
  • 2020-02-12
  • 2016-07-14
  • 2018-04-16
  • 2016-03-24
  • 1970-01-01
  • 2017-11-05
  • 2021-08-25
  • 1970-01-01
  • 2019-05-12
相关资源
最近更新 更多