1

我有一个 ajax,我不知道它是否正确。我想从控制器中获取值并将其传递给 ajax。

阿贾克斯:

$.ajax({
    type: "GET",
    url: swoosh(id, path+'swoosh_employee/swoosh_delete_child', 'childdv'),
    success: function(response) {
      if (response != "Error")
        { 
            $('#success-delete').modal('show');
        } 
        else 
        { 
        alert("Error"); 
        }
    }
  });
 event.preventDefault();

在控制器中:

 public function swoosh_delete_child()
{
    $P1 = $this->session->userdata('id');
    parse_str($_SERVER['QUERY_STRING'],$_GET);
    $id = $_GET['h'];

    $response = $this->emp->delete_children($id);
}

模型

public function delete_chilren($id){
.......//codes here.. etc. etc.
if success // 
 return "success";
else
 return "Error";
}

我只想传递/获取 $reponse 的值并将其传递给 ajax 并检查该值是否错误..

4

2 回答 2

2

只需在控制器中回显:

$response = $this->emp->delete_children($id);

alert回应:

alert(response); //output: success / Error
于 2013-11-14T09:52:58.260 回答
1

在您的控制器中:

你应该有这样的东西

public function swoosh_delete_child(){

$P1 = $this->session->userdata('id');
parse_str($_SERVER['QUERY_STRING'],$_GET);
$id = $_GET['h'];

$response['status'] = $this->emp->delete_children($id);
  echo json_encode($response);
}

然后在你的ajax中,访问响应

 $.ajax({
  type: 'POST',
  url: url: swoosh(id, path+'swoosh_employee/swoosh_delete_child', 'childdv'),,
  dataType: 'json',
  success: function(response){
  if (response.status)
    { 
        $('#success-delete').modal('show');
    } 
    else 
    { 
    alert("Error"); 
    }
  }
});
于 2013-11-14T09:58:05.837 回答