如何绑定'文本'使用json进行ajax调用时的数据类型结果集?

时间:2016-08-03 03:05:18

标签: php jquery ajax model-view-controller

我正在寻找这种情境的解决方案。 我请求ajax调用从数据库中获取四组数组值。

  

Ajax Call

$.ajax({
    url: "/process/loadContractTabs", 
    type: "GET",
    data:{
          id : id
         },
    dataType: "json",
    async: true,
    success: function (data) {
          console.log(data);
          if(data['resident'].length > 0){
                 // do the actions here                                                                                                                                        
          }
          if(data['charge'].length > 0){
                 // do the actions here                                                                                            
          }
          if(data['amount'].length > 0){
                 // do the actions here                                                                                            
          }
          if(data['tenancy'].length > 0){
                 // do the actions here                                                                                            
          }
    },
    error: function (data) {
          alert("Error in internet Connection..!\n\nTry agains." + "-"+data);
          window.location.reload(true);
    }
  

控制器操作

    public function loadContractTabs(){
        if(isset($this->registry->data['id'])){
            $process=new process();
            $data = array();
            $data['resident'] = $process->loadContractResidentTab($this->registry->data['id']);
            $data['charge'] = $process->loadContractChargeTab($this->registry->data['id']);
            $data['amount'] = $process->loadContractAmountTab($this->registry->data['id']);    
            $data['tenancy'] = $process->loadContractTenancyTab($this->registry->data['id']);
            echo json_encode($data);
        }
    }

正如我在控制器操作中所提到的,我要求将这四组数组作为json访问视图。除 $ data [' tenancy'] 之外,其余数组集将其值视为预期的json。

$ data [' tenancy'] 数组处理' text'数据类型值在模型类中如下所示。

    public function loadContractTenancyTab($id){
        $sql = "SELECT cmctd.id,cmctd.description FROM `cms_mstr_contract_tenancy_detail` AS cmctd WHERE cmctd.contract_id=:id";
        $data ['id'] = array ($id, 'int' );
        parent::prepare ( $sql );
        parent::databind ( $data );
        $result = parent::execute ();
        return $result;
    }

enter image description here

如何克服此问题将json的所有值集合到视图中?如果没有建议你最好的解决方案。

提前致谢

0 个答案:

没有答案