在控制器中没有工作检查请求...检查后必须发送数据发送到模型

时间:2015-05-11 11:01:33

标签: php jquery codeigniter

在通过模型的发布请求值获取数据后,将值发布请求发送到控制器后检查复选框 view(onlineorder / index.php)

<script src="<?php echo base_url('assets/js/ajax.jquery.min.js'); ?>"></script>
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>

<script src="<?php echo base_url('assets/fullcalendar/moment.min.js'); ?>"></script>
<script src="<?php echo base_url('assets/fullcalendar/jquery.min.js'); ?>"></script>



<?php echo form_open('onlineOrder/index'); ?>
<div class="row">
    <div class="col-md-6">
        <div class="form-horizontal well">
            <fieldset>
                <label>Захиалга өгөх тасаг сонгох</label>
                <div class="tree-wrap">
                    <ul>                                                        
                        <?php
                        $counter = 0;
                        $getData = $getDataOrgBranch['listBranch'];
                        foreach ($getData as $value) {
                            echo '<li><input type="checkbox" value="' . $value['branch_id'] . '" class="event-branch"><span><i class="fa fa-folder-close-alt"></i>' . $value['branch_name'] . '</span></li>';
                        }
                        ?>
                    </ul>
                    <input type="button" value="Get checkboxes" id="getCheckboxesButton">
                    <div id="debugOutput"></div>
                </div>                                                  
            </fieldset>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-horizontal well">
            <fieldset>
                <label>Захиалга өгөх үйлчилгээ сонгох</label>
                <div class="tree-wrap">
                    <ul>
                        <?php
                        foreach ($getDataOrgService as $selectedObj) {
                            echo '<li class="collapsed"><input type="checkbox"><span><i class="fa fa-folder-close-alt"></i>' . $selectedObj["title"] . '</span>';

                            if (array_key_exists("children", $selectedObj)) {
                                $data = $selectedObj["children"];
                                echo "<ul>";
                                foreach ($data as $val) {
                                    echo '<li class="leaf"><input type="checkbox"><span><i class="fa fa-folder-close-alt"></i>' . $val["title"] . '</span></li>';
                                }
                                echo "</ul>";
                            }
                            echo "</li>";
                        }
                        ?>  
                    </ul>
                </div>                                                  
            </fieldset>
        </div>
    </div>
</div>  
</form>

<script>
    $(document).ready(function () {

        $('.event-branch').change(function () {

            if ($(this).is(":checked")) {

                var checkVal = $(this).val();

                $.ajax({
                    url: "<?php echo base_url('onlineOrder/index'); ?>",
                    type: "POST",
                    data: {"branchId": checkVal},
                    dataType: "json",
                    success: function (getDataServiceOfBranch) {
                        alert("8888888888888888" + data);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        console.log(jqXHR);
                        console.log(textStatus, errorThrown);
                    }
                });
            }

            console.log(checkVal);
        });

    });

</script>

控制器(OnlineOrder.php)

&#13;
&#13;
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class OnlineOrder extends CI_Controller {

    function __construct() {
        parent::__construct();        
        $this->load->model('menusModel');
        $this->load->model('getFromDataUrlModel');
    }

    public function index() {
        if (isset($_POST['branchId'])){
            $id = $this->input->post('branchId');
            $data['getDataServiceOfBranch'] = $this->getFromDataUrlModel->getDataServiceOfBranch($id);        
        }
        $head['page'] = 'onlineorder';
        $head['menus'] = $this->menusModel->getAllData();
        $head['getDataOrgAndEmployee'] = $this->getFromDataUrlModel->getDataOrgAndEmployee();
        $data['getDataOrgService'] = $this->getFromDataUrlModel->getDataOrgService();
        $data['getDataOrgBranch'] = $this->getFromDataUrlModel->getDataOrgBranch();
        $this->load->view('header', $head);
        $this->load->view('onlineorder/Index',$data);
        $this->load->view('footer');
    }
}
&#13;
&#13;
&#13;
&#13;
&#13;
<p>Model(GetFromDataUrlModel.php)</p>
<!-- begin snippet: js hide: false -->
<?php

class GetFromDataUrlModel extends CI_Model{

function __construct()
{
	// Call the Model constructor
    parent::__construct();
    $this->load->helper('url');
}

public function getDataServiceOfBranch($id='')
{        
    $url = 'http://192.168.1.22:9390/HomePage/TreatmentByBranch?branch_id='. $id;
    $orgBranchService = json_decode(file_get_contents($url), true);

    return $orgBranchService;

    $file_headers = @get_headers($url);
    if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
        echo show_404();
    }
    else {

    }
}
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我无法理解您的问题是什么,但我认为您的代码需要这些修改才能正常运行,请使用以下内容更新您的控制器和模型,并查看是否可以解决此问题。

控制器索引:

public function index() {

        $id = $this->input->post('branchId');
        if ($id) {
            $data['getDataServiceOfBranch'] = $this->getFromDataUrlModel->getDataServiceOfBranch($id);
            if (!$data['getDataServiceOfBranch'])
            {
                echo show_404();
            }
        }

        $head['page'] = 'onlineorder';
        $head['menus'] = $this->menusModel->getAllData();
        $head['getDataOrgAndEmployee'] = $this->getFromDataUrlModel->getDataOrgAndEmployee();
        $data['getDataOrgService'] = $this->getFromDataUrlModel->getDataOrgService();
        $data['getDataOrgBranch'] = $this->getFromDataUrlModel->getDataOrgBranch();

        $this->load->view('header', $head);
        $this->load->view('onlineorder/Index', $data);
        $this->load->view('footer');
    }

模型方法:

public function getDataServiceOfBranch($id)
{        
    $url = 'http://192.168.1.22:9390/HomePage/TreatmentByBranch?branch_id='.$id;
    $orgBranchService = json_decode(file_get_contents($url), true);

    $file_headers = @get_headers($url);

    if ($file_headers[0] == 'HTTP/1.1 404 Not Found') {
        return false;
    }

    else {
        return $orgBranchService;
    }
}

希望它有所帮助。