在同一 ajax 调用中更新和获取数据
Update and get the data in the same ajax call
我正在尝试从ajax调用中的数据库一次更新和获取更新的行
就绪函数中的 JS
$("button[name='teacher_lock_exam']").on(ace.click_event, function () {
var current_exams_id = $(this).attr('id');
bootbox.confirm("Are you sure you want to lock the exam? <br/><br/>" +
"Locked exam cannot be modified until exam committee unlock it.", function (result) {
if (result) {
lock_exam(current_exams_id);
bootbox.alert("Your Exam has been Locked !<br/><br/> Contact with Exam committee to modify that exam again.");
}
});
});
function lock_exam(current_exams_id) {
$.ajax({
url: "teacher_internal_exam_management/lock_exam/" + current_exams_id,
type: "POST",
dataType: "json",
success: function (row) {
alert('success');
alert(row[0].access_status);
}
});
}
我的teacher_internal_exam_management控制器
public function lock_exam($current_exams_id)
{
$this->load->model('teacher_internal_exam_management_model');
$this->teacher_internal_exam_management_model->lock_exam($current_exams_id);
echo (json_encode($this->teacher_internal_exam_management_model->get_exam_details($current_exams_id)));
}
我的teacher_internal_exam_management_model模型
function lock_exam($current_exam_id, $data)
{
$this->db->query("update current_exams set access_status = 'locked' where current_exams_id='".$current_exam_id."'");
}
function get_exam_details($exam_id)
{
$query = $this->db->query("select * from current_exams
where
current_exams_id = '" . $exam_id . "'
");
return $query->result();
}
现在,ajax 调用正在更新数据,但控制器中的回显不会返回该行。意味着 ajax 的成功函数没有运行。为什么这不起作用?代码有问题吗?
模型的最后一行:
return $query->result();
http://ellislab.com/codeigniter/user-guide/database/results.html
This function returns the query result as an array of objects, or an empty array on failure.
这将返回一个对象数组。
您必须适当地转换它 -
return $query->result_array();
根据 http://www.php.net/manual/en/class.mysqli-result.php 年的 php 手册,我没有看到类型 mysqli_result 的 result(( 方法。我认为你需要使用
return $query->fetch_all();
而不是
return $query->result();
相关文章:
- 输入字段将't获取更新的值
- 获取Div Width,然后更新Scope Variable
- 获取 HTML 5 音频控制文件位置并在不使用 id 选择器的情况下更新 src
- 更新Redux状态&然后在同一实例中获取更新状态
- 循环遍历表行,获取总计和更新行
- 如何在 JavaScript 中获取下一个元素和更新
- 在谷歌地图 API v3 中获取更新的半径/面积
- 更新后,Laravel/Ajax从数据库获取值
- 正在尝试获取事件之外的更新数组的值
- 如何获取数据属性中存在的现有JSON并更新它
- 获取ng中的更新值重复Angular JS
- 如何在客户端的元窗口小部件(JavaScript)中获取和显示更新的域模型
- 主干.js更改模型的 url 参数,提取不会更新获取的数据
- 根据另一个字段选择获取新值后更新下拉列表内容
- Three.js:使用变形目标获取更新的顶点
- 无法获取onchange以触发innerHTML更新
- 获取更改图像宽度的即时更新
- X-editable:如何获取每行的id,以便更新单个成员
- 在react组件中使用ajax获取实时更新的数据
- 实时更新获取请求