gpt4 book ai didi

javascript - Codeigniter:Ajax 发送 id 和名称,但函数仅接收 id

转载 作者:行者123 更新时间:2023-11-27 22:56:41 25 4
gpt4 key购买 nike

我得到了 ID,但没有得到姓名,我做错了什么?请看下面我的 CI 代码和 ajax 函数:
这是我调用 ajax 的 View:

 <div class="modal fade" id="myModal<?php echo $values->season_id; ?>"
tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Update Seasons</h4>
</div>
<div class="modal-body">
<div class="form-group">
<input type="hidden" id="hiddenValue" name="hiddenValue" value="<?php echo $values->season_id; ?>">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">Season Name:
</label>
<div class="title_right">
<div class="input-group">
<input type="text" class="form-control" name="update_name" id="update_name" value="<?php echo $values->names; ?>">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" id="submit" value="Save changes">
</div>
</div>
</div>
</div>

这是 Ajax 函数:

<script type="text/javascript"> 
// Ajax post
$(document).ready(function()
{

alert("Ajax function started working");

$("#submit").click(function(event)
{
event.preventDefault();
var hiddenValue = $("#hiddenValue").val();

alert(hiddenValue);

var update_name = $("input#update_name").val();

// pop up Name Entered
alert(update_name);

jQuery.ajax(
{
type: "POST",
url: "<?php echo base_url(); ?>" + "seasons/update_season",
dataType: 'json',

data: {
hiddenValue : hiddenValue,
update_name: update_name
},

success: function(res)
{
console.log(res);
// window.alert("i got some data ");
if (res)
{
alert("changes made");
}
}
});
});
});

在这里我试图捕捉值(value):

public function update_season()
{
$session_id = $this->session->userdata('id');
if (isset($session_id))
{
$update_id = $this->input->post('hiddenValue');
$update_name = $this->input->post('update_name');

$result = $this->model_season->update_season($update_id,$update_name);

if ($query)
{
$query = $query->row();
$data = array(
'season_id' => $query->season_id,
'names' =>$query->names
);
echo json_encode($data);
}
else
{
return FALSE;
}

}
else
{
redirect('user_authentication');
}
}

最佳答案

您使用

 if ($query) 
{
$query = $query->row();
$data = array(
'season_id' => $query->season_id,
'names' =>$query->names
);
echo json_encode($data);
}

但是你的$query在哪里。作为您的代码,它应该具有以下内容

if ($result) 
{
$data = array(
'season_id' => $result->season_id,
'names' =>$result->names
);
echo json_encode($data);
}

现在使用 $result->season_id 而不是 $query->season_id 并确保在模型中使用 row() 方法update_season() 用于返回所需值

关于javascript - Codeigniter:Ajax 发送 id 和名称,但函数仅接收 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37537979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com