Home >Backend Development >PHP Tutorial >ajax asynchronous request refresh method

ajax asynchronous request refresh method

小云云
小云云Original
2018-01-12 17:10:021738browse

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

Among the methods of website refresh, ajax refresh is a refresh 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";

  };

Related recommendations:

javascript - ajax refresh problem

php +ajax creates a non-refresh message board, phpajax refreshes the message board_PHP tutorial

php+ajax implements non-refresh paging, phpajax refreshes the paging

The above is the detailed content of ajax asynchronous request refresh method. 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