据我所知,这段代码应该可以正常工作,但由于某种原因它无法正常工作。有人能帮帮我吗?!!T_T
js脚本:
$.ajax({
type: 'POST',
url: '<?=base_url()?>/folder_name_ajax/unit_vacancy',
dataType: 'json',
data:{unit_id:unit_id, unit_landlord_id:unit_landlord_id, unit_stat:unit_stat},
beforeSend: function(){
},
success: function(response){
console.log(response);
alert('Unit status successfully updated.');
}
});
控制器:
function unit_vacancy()
{
$this->load->model('modelAjax');
$unit_id = mysql_real_escape_string($this->input->post('unit_id'));
$unit_landlord_id = mysql_real_escape_string($this->input->post('unit_landlord_id'));
$unit_stat = mysql_real_escape_string($this->input->post('unit_stat'));
$xplod_stat = explode('-',$unit_stat);
$this->modelAjax->update_unit_vacancy();
}
模型:
function update_unit_vacancy()
{
$unit_id = mysql_real_escape_string($this->input->post('unit_id'));
$unit_landlord_id = mysql_real_escape_string($this->input->post('unit_landlord_id'));
$unit_stat = mysql_real_escape_string($this->input->post('unit_stat'));
$xplod_stat = explode('-',$unit_stat);
$result = $this->db->query("SELECT COUNT(ID) AS count FROM ".TBL_PREFIX."".UNIT_VACANT_TBL." WHERE unit_id = '$unit_id' ");
$count = $result->num_rows();
if($count == 0)
{
$result = $this->db->query("INSERT INTO ".TBL_PREFIX."".UNIT_VACANT_TBL."
(
unit_id,
landlord_id,
status
)
VALUES
(
'$unit_id',
'$unit_landlord_id',
'insert'
)
");
}
else
{
$result = $this->db->query("UPDATE ".TBL_PREFIX."".UNIT_VACANT_TBL."
SET
status = 'update'
WHERE
unit_id = '$unit_id'
");
}
}
我似乎无法理解我在这里做错了什么!!!