jQuery Ajax()方法使用指南(2)


function getMyPrizeList(){
    if(isNotEmpty(uid)){
        var obj=new Array();
        try{
                  jQuery.ajax({type:"GET",url:"someurl",
                               cache:false,
                               dataType:"script",
                               scriptCharset:"gbk",
                               success:function(json){
                                 try{
                                      obj=result; 
                                }catch(e){}
                                jQuery("#prizelist").html("");
                                var str="";
                                for(var i=0;i<obj.length;i++ ){
                                    str+='<tr><th>'+prizearray[obj[i].prizeno]+'</th>';
                                    str+='<td>CD-KEY:'+obj[i].cdkey+'</td>';
                                    str+='<td>期限:'+obj[i].expiratedate+'前</td></tr>';
                                }
                                jQuery("#prizelist").append(str);                  
                               }
                   });
           }catch(e){}
        }
}

6. jQuery.getJSON实例:

复制代码 代码如下:


//内部函数,实现债务人详细信息的载入、设置值
    function innerShowDetail() {
       // 获得JSON格式的数据
       $.getJSON('load.do',{id : userId}, function(json) {
           // 根据key设置value
           for (key in json) {
              if(key == 'id'){
                  $('#detailDiv #' + key).val(json[key]);
              } else {
                  if(json[key] == ''){
                     // 没有值设置为空
                     $('#detailDiv #' + key).html(' ');
                  } else if(key == 'sex'){
                     $('#detailDiv #' + key).html(json[key] == '0' ? '女' : '男');
                  } else if(key == 'group'){
                     if(json[key] != null) {
                         $('#detailDiv #' + key).html(json[key]['groupName']);
                     }
                  } else {
                     $('#detailDiv #' + key).html(json[key]);
                  }
              }
           }
           //设置对话框标题和内容
           $('#detailDiv').removeAttr('class');
           dialog.setTitle('查看人员[' + json['userName'] + ']详细资料');
           dialog.setContent($('#detailDiv').html());
       });
    }

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgswfd.html