-1

据我所知,这段代码应该可以正常工作,但由于某种原因它无法正常工作。有人能帮帮我吗?!!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' 
                                  ");
    }
}

我似乎无法理解我在这里做错了什么!!!

4

1 回答 1

1

echo(ing)如我所见,您在控制器中什么都不是。?你在哪里json?你update_unit_vacancy()退货了json吗?如果yes那么echo它。

 echo $this->modelAjax->update_unit_vacancy();

并检查您的控制台是否有 ajax 的响应。不过,建议您再做一件事,更改以下行:

url: '<?=base_url()?>index.php/rentdaddy_ajax/unit_vacancy',
于 2013-10-24T11:42:04.213 回答