json_encode 数据返回

if(count($listAddress)>0){

            echo json_encode(array('res'=>'成功','status'=>1,'info'=>$listAddress));
        }else{
            echo json_encode(array('res'=>'失','status'=>0));

        }


<script type="text/javascript">      //属性操作 - removeClass() 方法
$(document).ready(function(){
  $("button").click(function(){
    $("p").removeClass("intro");
  });
});
</script>

// Display a warning toast, with no title
toastr.warning( 'My name is Inigo Montoya. You killed my father, prepare to die!' )
 
// Display a success toast, with a title
toastr.success( 'Have fun storming the castle!' , 'Miracle Max Says' )
 
// Display an error toast, with a title
toastr.error( 'I do not think that word means what you think it means.' , 'Inconceivable!' )
 
// Clears the current list of toasts
toastr.clear()

 toast.success(11);

console.log('aaaaaaaaaa');


先执行此处:

<script>
        $(document).ready(function(){
        $('.prov{$k}').click(function(){
        var prove = '{$vo['province']}';
        $.post(U('Shop/Order/ajaxValue'),{name:prove},function(data){
        //alert(data.info.14.goods_address);
         if(data.status==1){
              toast.success(11);
              alert(data['info'][14]['goods_address'])

            
           }else{
                toast.error(222);
            
           }
          
        },"json"); //加这个转换成JSON 形式
        });


        });
    </script>

再执行下面:

//商品的运费信息
    public function ajaxValue($name='')
    {
        $fr=D('shop_freight');
        //$list = $fr->order('f_id')->limit(1)->find();
        $listAddress=$fr->order('f_id')->where('f_id>1  and goods_address like "%'.$name.'%"')->getField('f_id,goods_address,f_money,f_num,f_freight');
        //echo D('shop_freight')->getLastSql();die;
    
        if(!empty($listAddress)){
            echo json_encode(array('res'=>'成功','status'=>1,'info'=>$listAddress));
        }else{
            echo json_encode(array('res'=>'失','status'=>0));
        }
        //echo D('shop_freight')->getLastSql();die;
        //$this->assign('listAddress',$listAddress);
        //$this->display("Index/goodsdetail");
    }


下面图片的不存在:默认显示:

$(window).load(function() { 
  $('img').each(function() {
    if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) { 
      this.src = 'http://www.tranism.com/weblog/images/broken.gif'; 
      } 
   });
});


先检查图片是否加载成功,然后如果失败的话再绑定事件。而且替换一次就好了。

<img src="xxxx.jpg" alt="" />

<script>
jQuery(document).ready(function(){
    jQuery('img').each(function(){
        var error = false;
        if (!this.complete) {
            error = true;
        }

        if (typeof this.naturalWidth != "undefined" && this.naturalWidth == 0) {
            error = true;
        }

        if(error){
            $(this).bind('error.replaceSrc',function(){
                this.src = "default_image_here.png";

                $(this).unbind('error.replaceSrc');
            }).trigger('load');
        }
    });
});
</script>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值