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 编码之一。在遍历警报时,我不是通过键或值来获取每个字符的值。有什么帮助吗?

4

1 回答 1

0

添加数据类型和内容类型解决了这个问题。添加了其他参考的完整代码。

     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
      });   
于 2012-06-07T13:38:38.797 回答