首页 > 解决方案 > 我的 AJAX POST 中的 500(内部服务器错误)

问题描述

我有一个取消招聘活动的按钮,其中包含一条使用甜蜜警报的确认消息,但随后确认该操作不会通过我的 ajax 帖子。

我尝试检查 url 是否正确,但话又说回来,所有 url 都是正确的。

这是我在控制器中的功能:

    {
        $hiring_id = $this->input->post('key');
        $hiring_data = $this->hiring_model->get_hiring($hiring_id);

        $return_a = $this->search_model->update_applicant($hiring_data[0]->applicant_id);

        $return_b = $this->search_model->cancel_hiring($hiring_id);

        if ($return_a > 0 && $return_b > 0) {
            echo json_encode(array('ret'=>'1','new_url'=>base_url('partners/hiring')));
        }
    }

这是我在 HTML 中的代码:

<button type="button" class="btn btn-danger btn-sm m-btn--custom" id="cancel_hiring" data-url="<?php echo base_url('partners/hiring/cancel_hiring/'); ?>" data-key="<?php echo $h->hiring_id;?>">

这是我的javascript:

<script>
    $(function(){
        $("#cancel_hiring").click(function(e){
            Swal.fire({
              title: 'Are you sure you want to cancel this hiring?',
              text: "You won't be able to revert this!",
              type: 'warning',
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: 'Cancel Hiring'
            }).then((result) => {
              if (result.value) {
                console.log($(this).data('url'));
                console.log($(this).data('key'));
                $.post($(this).data('url'), {key:$(this).data('key')}, function(data) {
                    console.log(data);
                    if (data.ret) {
                        console.log('cancelled');
                        Swal.fire(
                          'Success!',
                          'Hiring cancelled.',
                          'success'
                        )
                        var delay = 1000; 
                        setTimeout(function(){ window.location = data.new_url; }, delay);
                    } else {
                        Swal.fire(
                          'Failed!',
                          'Error occured.',
                          'warning'
                        )
                    }
                }, 'json');

              }
            })
        });
    });
</script>

标签: javascriptphpjqueryajaxcodeigniter

解决方案


推荐阅读