javascript - 我的 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>
解决方案
推荐阅读
- swift - Swift pdf没有覆盖tableview中的所有单元格
- c++ - LIBAV MJPEG 编码和霍夫曼表
- jenkins - 在 Jenkins 中使用 ant 命令运行 Ansible playbook
- visual-foxpro - Microsoft Visual Foxpro OleDb 提供程序错误:System.Data.OleDb.OleDbException:“功能不可用。”
- oracle - 此上下文中不允许表、视图或序列引用“LN_GRAPH_PERC.DATE_RED”
- python - 合并数据框,添加/更新字段
- azure-api-management - 如何在 Azure API 管理中导入 swagger
- android - RecyclerView 不显示
- makefile - 是否可以在 Makefile 中使用模式将文件名中间从源映射到目标?
- nestjs - 迁移已添加到根文件夹而不是迁移文件夹