在我的应用程序的 view_candidates
表单中,我有一个带有文本的按钮 REQUEST CONTACT INFO
。当我点击按钮时,文本将自动更改为 FINISH
。
现在发生了什么: 当我刷新页面时,按钮文本自动更改为 REQUEST CONTACT INFO
。
为了克服这个问题,我在我的数据库中提供了一个 status
列。
我想要的是:
一旦用户点击按钮, status
应该从 0 变为 1。
使用 status
,我想显示我的按钮文本,如:if status=0 button should be REQUEST CONTACT INFO
,否则它应该是 FINISH
按钮代码:
<td>
<button type="button" id="button" class="btn btn-info" onclick="getConfirmation(id);">
<b>REQUEST CONTACT INFO</b>
</button>
</td>
脚本:
<script>
function getConfirmation(id)
{
var retVal = confirm("your request is confiremed ?");
if(retVal)
{
$('#button').text('Finish');
$.ajax({
url: "Candidate/user_view_candidates/change_status",
type: "post",
data: id,
success: function (response)
{
//location.reload();
alert('success');
}
});
}
}
</script>
控制器代码:
public function change_status()
{
$id = $this->input->post('candidate_id');
$status = $this->db->query("select status from candidates_details where id = candidate_id")->row()->status;
if($status==0)
{
$status = 1;
}
else
{
$status = 0;
}
$data=array('status'=>$status);
$this->db->where('candidate_id',$id);
$this->db->update('candidates_details',$data);
}
有人能帮我吗?
提前致谢。
原文由 M5533 发布,翻译遵循 CC BY-SA 4.0 许可协议
检查这个:
看法
js
控制器
模型