2012-06-04 3 views
0
public function actionajaxSearch() { 
     $data_fetched=Person::model()->findByAttributes (array('Code'=>'Cust0001')); 
     echo CJSON::encode($data_fetched); } 



    $('#searchResult').live('pageshow', function(e,info) 
    { 
    $.post('?r=mobile/ajaxSearch',$('form').serialize(), 
    function(res) 
    {   
    arrayvalue =res;   
    $.each(arrayvalue, function(i, profile) { 
     alert(i); 
     alert(profile); 
    }); 
     } 
    }); 

출력을 json encode로 출력하고 있습니다. 탐색 경고에서 키 또는 값이 아닌 각 문자의 값이 표시됩니다. 도움이 되었습니까?jquerymobile에서 ajax json 출력 구문 분석

+0

이런 식으로 시도해 보셨나요? arrayvalue = res.d; 또한 arrayvalue에 도움이되는 형식을 기록하십시오. – Tamkeen

답변

0

데이터 유형 및 contenttype을 추가하면 문제가 해결되었습니다. 다른 사람의 심판에 대한 완전한 코드가 추가되었습니다.

 public function actionajaxSearch() { 
    $data_fetched=Person::model()->findByAttributes (array('Code'=>'Cust0001')); 
    echo CJSON::encode($data_fetched); } 



     $('#searchResult').live('pageshow', function(e,info) 
     { 
     $.ajax({ 
      beforeSend: function() { $.mobile.showPageLoadingMsg(); }, 
      complete: function() { $.mobile.hidePageLoadingMsg() }, 
      url: '?r=mobile/ajaxSearch', 
      data: $('form').serialize(), 
      type: 'POST', 
      ContentType: "application/json", 
      dataType: "json", 
      success:function(res) { 
       if(res !='') 
       { 
       $.each(res, function(key, value) { 
        var li='<li><a href="#">'+value['Code']+'</a></li>'; 
        $("#mylist").append(li); //append li to ul of id list 

       }); //eachfunction 
       $('#mylist').listview(); 
       $('#mylist').listview('refresh'); 
     }//sucess 
     });