判断返回的对象是否为空

用$.isEmptyObject(对象)来判断 空返回true 否则为false

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- 引入jquery.js -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>

<script type="text/javascript">
  $(function () {
            $("#sb").click(function () {
         
           
		var str = document.getElementById("su");
		var st=str.value;
		

		
		
            $.ajax({


                url:"/Home/mail/find",
                data:{number:st},
                dataType:"json",
                success:function (mobile) {
                console.log($.isEmptyObject(mobile.mobileNumber));
                console.log(mobile);
                if(!$.isEmptyObject(mobile.mobileNumber)){//不为空
                
                     console.log(mobile);
                     var msg = mobile.mobileNumber+"=>"+mobile.mobileArea+"=>"+mobile.mobileType;
                    $("#result").html(msg);
                    
                    }else{
                    
                     $("#result").html("不存在");
                     
                     }
                
                }




            })


        })

 });


</script>

</head>
<body>
<form  >
<input  id="su" type="text" name="number">
<input id="sb" type="button" value="查询归属地">

</form>

<div id="result"></div>
</body>
</html>

  

posted @ 2018-05-10 20:44  城南少年与猫  阅读(1629)  评论(0编辑  收藏  举报