请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

文章审核,数据库已经更新了,但是网页不更新,status显示500错误

Chrome:

Request URL:

http://127.0.0.1:8000/admin/posts/51/status

Request Method:

POST

Status Code:

500 Internal Server Error

Remote Address:

127.0.0.1:8000

Referrer Policy:

no-referrer-when-downgrade

post/index.blade.php

@foreach($posts as $post)
   <tr>
       <td>{{$post->id}}.</td>
       <td>{{$post->title}}</td>
       <td>
           <button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" post-action-status="1" >通过</button>
           <button type="button" class="btn btn-block btn-default post-audit" post-id="{{$post->id}}" post-action-status="-1" >拒绝</button>
       </td>
   </tr>
@endforeach

PostController@status

public function status(Post $post)
{
   $this->validate(request(), [
       "status" => 'required|in:-1,1',
   ]);

   $post->status = request('status');
   $post->save();
   return [
       'error' => 0,
       'msg' => ''
   ];
}

正在回答 回答被采纳积分+3

1回答

提问者 慕慕5403139 2017-12-15 02:25:00
javascript如下:
/* ajax csrf-token */
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$(".post-audit").click(function (event) {
    target = $(event.target);
    var post_id = target.attr("post-id");
    var status = target.attr("post-action-status");

    $.ajax({
        url: "/admin/posts/" + post_id + "/status",
        method: "POST",
        data: { "status": status },
        dataType: "json",
        success: function success(data) {
            if (data.error != 0) {
                alert(data.msg);
                return;
            }

            target.parent().parent().remove();
        }
    });
});


0 回复 有任何疑惑可以回复我~
  • 提问者 慕慕5403139 #1
    晕,查了一天才发现$post->save();报错,用tinker发现Elasticsearch\Common\Exceptions\Curl\CouldNotConnectToHost with message 'cURL error 7: Failed to connect to 127.0.0.1 port 9200: Connection refused'
    elastisearch没开启,开启之后就可以了,郁闷啊~~~
    回复 有任何疑惑可以回复我~ 2017-12-16 01:27:01
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号