【问题标题】:Internal 500 error on ajax postajax 帖子上的内部 500 错误
【发布时间】:2013-04-19 00:34:24
【问题描述】:

我正在尝试在我们的 ajax 上发布更新用户元数据的请求(这不是 wordpress 相关的问题)。我这样做的方式是,我使用带有 .position 的 jquery 可拖动 UI 来检索 position.top 编号,在 stop() 处我调用了将值发布到 ajax 文件的函数。出于某种原因,它返回 500 内部错误并使我们的 ajax 文件对所有其他功能无效。

这是第一步 $(document).ready(function() {

                $(".top_image_roll").hide();

            $(".five img").draggable({
                axis: "y",
                // Find original position of dragged image.
                start: function(event, ui) {

                    // Show start dragged position of image.
                    var Startpos = $(this).position();
                },

                // Find position where image is dropped.
                stop: function(event, ui) {

                    // Show dropped position.
                    var Stoppos = $(this).position();
                    update_image_coords_1(Stoppos.top);

                }
            });
            });
            </script>
        <?php } else { ?>           
        <?php }?>

这是函数

function update_image_coords_1(coordss) {

  $.post('http://xxx/xxx/xxx/xxx/ajax.php',
    {
      'action': 'update_image_coords_1',
      'coords': coordss,
      'user_id': '<?php echo $user_id; ?>'

    }
  );
}

这是在 ajax 文件中

if( !empty($_REQUEST['action']) && $_REQUEST['action'] == 'update_image_coords_1' && !empty($_REQUEST['user_id']) && !empty($_REQUEST['coords'])) {

$coords = $_REQUEST['coords'];
update_user_meta($_REQUEST['user_id'], 'update_image_coords_1', $coords); 
die();
}

我做错了什么吗?还有其他建议吗?提前致谢

【问题讨论】:

  • 您的 PHP 文件的语法无效 - if 语句没有足够的右括号。我相信,在最后两次调用 empty 之后,您需要一个额外的。
  • 为什么最后使用 die() ?这可能是问题所在。
  • andrewsi....我刚刚注意到....我正在检查
  • @JasonKaczmarsky 'die()' 在 wordpress ajax 函数中是必需的
  • 我检查了右括号,它们是正确的。

标签: php javascript ajax jquery-ui


【解决方案1】:

empty 调用后,您的 if 语句缺少几个右括号:

if( !empty( $_REQUEST['action']) && $_REQUEST['action'] == 'update_image_coords_1' && !empty($_REQUEST['user_id'] && !empty($_REQUEST['coords']) {

应该是:

if( !empty( $_REQUEST['action']) && $_REQUEST['action'] == 'update_image_coords_1' && !empty($_REQUEST['user_id']) && !empty($_REQUEST['coords'])) {

【讨论】:

  • 谢谢大家的意见
【解决方案2】:

内部 500 可能意味着您的 PHP 代码中有语法错误/其他致命错误。
如 cmets 中所述,您的 if 语句位于一堆括号中。

您应该做的是打开 Apache 错误日志,问题会非常好地呈现出来供您修复。

【讨论】:

  • 这是一个wordpress函数Itay。
  • @Nikolaos Vassos 我在发布几秒钟后删除了这个,有时我的齿轮需要几秒钟才能点击到位
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-20
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-12
相关资源
最近更新 更多