jQuery Ajax

<script>
             $("#userName").blur(function(){
                
                 $.post("UserNameTest","userName="+$("#userName").val(),function(response){
                     $("#msg").html(response);
                 });
             })
        </script>
<script>
  var obtn=document.getElementById("btn");
  obtn.onclick=function(){
      
      var xhr=new XMLHttpRequest();
      xhr.open("get","PersonServlet","true");
      xhr.send();
      xhr.onreadystatechange=function(){
          if(xhr.readyState==4 && xhr.status==200){
              var obj=JSON.parse(xhr.responseText);
              alert(obj.id);
              
          }
      }
  }
</script>
<script>
   $(function(){
       $("#btn").click(function(){
           $.ajax({
               type:"GET",
               url:"TestJson",
               dataType:"json",
               success:function(response){
                   for(var i=0;i<response.length;i++){
                       $("<tr>"
                               +"<td>" +response[i].name+"</td>"
                               +"<td>"+response[i].age+"</td>"
                          +"</tr>"
                       ).appendTo("#tab");
                   }
               }
           });
       });
   })
  </script>

 

posted on 2017-11-27 18:04  达摩克利斯  阅读(87)  评论(0编辑  收藏  举报

导航