jquery getJSON 请求数据并显示

180it 2021-12-26 PM 1678℃ 0条
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery jQuery click() 事件</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>

<!-- Bootstrap CSS -->

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>

<div class="card">
<div class="card-body">

<div class="row g-3">

<div class="col-auto">

<label for="staticEmail2" class="visually-hidden">Email</label>
<input id="tel" class="form-control" type="text"   placeholder="请输入收货人的手机号">
</div>

<div class="col-auto">

<button type="submit" class="btn btn-primary mb-3" onclick="get_trans()">查询</button>
</div>
</div>





 <ul class="mui-table-view" id="ullist" style="display:none">
          <li class="mui-table-view-cell">
            参赛姓名<span id="name" class="mui-pull-right mui-text-muted"></span>
          </li>
          <li class="mui-table-view-cell">
            手机号<span  id="tel1" class="mui-pull-right mui-text-muted">12</span>
          </li>
          
          <li class="mui-table-view-cell">
            地区<span id="area" class="mui-pull-right mui-text-success "></span>
          </li>
          <li class="mui-table-view-cell">
            邮寄地址<span id="addr" class="mui-pull-right mui-text-success "></span>
          </li>
          <li class="mui-table-view-cell">
            物流单号<span id="ordernum"  class="mui-pull-right mui-text-success"></span></li>
            <li class="mui-table-view-cell">
            物流公司<span id="company"  class="mui-pull-right mui-text-success "></span>
          </li>
          
 </ul>
 
 
 
  <ul class="mui-table-view" id="ullist2" style="display:none">
          <li class="mui-table-view-cell">
            <span id="info" class="mui-pull-right mui-text-muted"></span>
          </li>
         
 </ul>
 
 
        
        
        

</div>
</div>

<script>

  function get_trans(){
      var tel=$('#tel').val();
      if(!tel){
          alert('请填写手机号');
      }
         
      url='https://dingdan.ip81.com/api_order1_json.php?s='+tel
      $.getJSON(url,function(res){
        if(res.code!=1){
           // alert('查询失败,请确认手机号');
            $('#ullist2').css('display','block')
            $('#ullist').css('display','none')
            $('#info').text('查询失败,请确认手机号')
            
        }else{
            $('#ullist').css('display','block')
            $('#ullist2').css('display','none')
            var s=res.data[0];
            if(s.dh){
                $("#ordernum").text(s.dh)  
            }else{
               $("#ordernum").text('正在发货中,请耐心等待')
            }
            
            $('#name').text(s.name)
            $('#tel1').text(s.tel)
            $('#area').text(s.region)
            $('#addr').text(s.address)
            $('#company').text(s.kd)
        }
        });
  }
</script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"; integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

</body>
</html>
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

jquery getJSON 请求数据并显示