Home  >  Article  >  Web Front-end  >  Using ajax to implement asynchronous refresh requests

Using ajax to implement asynchronous refresh requests

亚连
亚连Original
2018-05-23 15:35:121659browse

ajax refresh is a refreshing method with good user experience. This article mainly introduces ajax asynchronous request refresh. Interested friends can refer to

Among the methods of website refresh, ajax refresh It is a refreshing method with good user experience, combined with popular frameworks such as ssh! The most commonly used! The following is a demo that commonly uses an ajax to refresh the form.

$(document).ready(function () {
  testchaxun();
   setInterval("testchaxun()",5000);
  });
  function testchaxun(){
    /* var selectId = $('#proviace').val(); */
    $.ajax({
    type : "POST",
     /* cache: false, */
    url : "WarningAction!warningdefQuery1.action",
    dataType : "json",
    success : function(data) {
      $('tr').remove('.datatr');
      for(var i=0;i<data.length;i++){
        if(data[i].pState == &#39;危险&#39;){
          $(&#39;.table-thtr&#39;).after(&#39;<tr class="datatr error-tr">&#39;+
           &#39;<td><img class="picture" src="&#39;+data[i].pPic+&#39;"/></td>&#39;+
           &#39;<td>&#39;+data[i].pName+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].uName+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].bHomenum+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].bNumber+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].eStart+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].wType+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].wTime+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].pAddress+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].uName+&#39;</td>&#39;+
           &#39;<td>&#39;+data[i].pState+&#39;</td>&#39;+
           &#39;<td><a href="WarningAction!waringInfor.action?WId=&#39;+data[i].wId +&#39;">详情</a></td>&#39;+
           &#39;</tr>&#39;);
        }else{
          $(&#39;.table-thtr&#39;).after(&#39;<tr class="datatr">&#39;+
         &#39;<td><img class="picture" src="&#39;+data[i].pPic+&#39;"/></td>&#39;+
         &#39;<td>&#39;+data[i].pName+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].uName+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].bHomenum+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].bNumber+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].eStart+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].wType+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].wTime+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].pAddress+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].uName+&#39;</td>&#39;+
         &#39;<td>&#39;+data[i].pState+&#39;</td>&#39;+
         &#39;<td><a href="WarningAction!waringInfor.action?WId=&#39;+data[i].wId+&#39;">详情</a></td>&#39;+
         &#39;</tr>&#39;);
        }

       }
     }
    });
   };
</script>

The WarningAction!waringInfor.action in the background receives and sends two parameters to realize the necessary conditions for requesting this method! Return a json

public String waringInfor(){
     w= warningService.getWarningByWid(WId);
     if (w!=null) {
       if (w.getPId()!=null) {
       p =patientService.getPatientByPId(w.getPId());
      }
    }
    if (p!=null) {
      if (p.getPId()!=null) {
        s= sickroomService.getSickroomByPid(p.getPId());
      }
      if (p.getPEquipmentid()!=null) {
        e= equipmentService.getEquipmentByEId(p.getPEquipmentid()); 
      }
    }
    return "waringInfor";

  };

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Ajax php realizes three-level linkage of product classification

About the output stream at the end of the servlet in Ajax technology

Ajax technology composition and core principle analysis

The above is the detailed content of Using ajax to implement asynchronous refresh requests. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn