Event response refresh: refresh only when requested 1. Get HTML elements through JS HTML DOM or jQuery, listen to page events through DOM methods or jQuery methods, and get user requests; 2. Submit the user request to the server through Ajax. The server returns the result after processing, and then Ajax receives the data. 3. Load data into the page through DOM method or jQuery method, and the event response refresh is completed. $('#input_date').keypress(function(e){ if(e.keyCode=='13'){ $.ajax({ type: "POST", url: "inquire_date.php", data: { birth:null, //1. Get user requests (ie certain events) and send them to the server for processing date:$('#input_date input').val() }, dataType: "json", //2. Get data from the server success: function(data){ if (data.success) { var festival = data.fetivalInquireResult; //3. Load the acquired data into the page to implement page event response refresh$('#show_festival').text(festival); } else { $('#show_festival').text("Failed to get festival"); } }, error: function(jqXHR){ alert("Error: " + jqXHR.status); }, }); $('#festival').hide(); $('#response_festival').show(); } }); Partial automatic refresh: The partial page will be automatically refreshed even if no request is made 1. Use a timer function such as setTimeout() to let Ajax get data from the server at regular intervals; 2. Load data into the page through DOM method or jQuery method to achieve automatic refresh of part of the page. $(document).ready(function(e){ setTimeout('updateShow()',0); }); /*Partial automatic refresh page data*/ function updateShow(){ $.ajax({ type: "GET", url: "inquire_date.php?data=" + "inquire", dataType: "json", //1. Get data from the server regularly through a timer success: function(data) { if (data.success) { var agesFormat = data.agesFormat; var daysFormat = data.daysFormat; //2. Load data into the page to achieve automatic refresh$('#ages').text(agesFormat); $('#days').text(daysFormat); } else{ alert("Failed to obtain data"); } }, error: function(jqXHR){ alert("Error: " + jqXHR.status); }, }); setTimeout('updateShow()',500); } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: How to insert Emoji expressions into MySQL
>>: Docker image creation, uploading, pulling and deployment operations (using Alibaba Cloud)
This article introduces a framework made by Frame...
Create docker-compose.yml and fill in the followi...
As a commonly used database, MySQL requires a lot...
environment Centos 6.6 MySQL 5.7 Install If the s...
Table of contents 1. Introduction to built-in obj...
The semantics, writing style, and best practices ...
In the following example, when the width of the td...
MySQL database reports ERROR 1045 (28000): Access...
Table of contents 1. Cause 2. Equipment Informati...
Preface tcpdump is a well-known command-line pack...
Unzip the file into a directory This is the direc...
1. Experimental Environment serial number project...
Based on the Vue image magnifier component packag...
As usual, today I will talk about a very practica...
Table of contents Overview 1. Define store.js 2. ...