1. interfaces for background data
The background mainly provides JSON serialized data. Any object can be serialized as a JSON string. After the object is serialized in the background, the string can be directly submitted to the foreground for deserialization into an object.
1. JSON interfaces:
1 // <summary> 2 // obtain the doctor's advice according to the time; 3 // </Summary> 4 // <Param name = "date"> </param> 5 // <returns> return the JSON serialized string </returns> 6 private string getaskadvisebyday (string date) 7 {8 list <docadvise> docadvise = pdao. getdocadvisebydate (list <docadvise>) session ["mongoad"], date, bday); // you can specify 9 mongocriptserializer JSS = new mongocriptserializer () by date (); // create a serialized object 10 string result = JSS. serialize (docadvise); // serialize the object to be returned as a JSON string 11 return result; 12 13}
2. Call the function 1 at the control layer of MVC and return the JSON result string:
1 /// <summary> 2 // asynchronous request for short doctor's advice 3 /// </Summary> 4 /// <Param name = "date"> </param> 5 /// <returns> </returns> 6 Public actionresult response=advise (string date) 7 {8 return content (getincluadvisebyday (date); 9 10}
Ii. asynchronous request data and Dom programming in front-end JS and jquery
1. Front-end HTML code:
1 <ul id = "emrlistview" data-role = "listview" data-inset = "true" style = "margin-top: 0px; "> 2 <li> <a href =" # "> </a> </LI> 3 <LI> <a href = "#"> </a> </LI> 4 </ul>
2. jquery asynchronous request data, Dom update
Main implementation process:
1) asynchronous request data, which returns data;
2) deserialize the returned data into a listurl object;
3) Add the data of the listurl object to the listview with the ID of emrgallery;
4) re-render the listview. This is a very important step that is often relatively easy to miss. With this step missing, the updated style of jquerymobile cannot be correctly rendered.
1 function reflashemr (time) {2 // asynchronous request data. Responseincluadvise is the function in control, time is the input parameter, and data is the returned JSON data 3 $. post (".. /ydylajax/responseappsadvise ", {" date ": time}, function (data, status) {4 var listurl = $. parsejson (data); 5 If (status = "success") {6 var objlistview = document. getelementbyid ("emrlistview"); 7 objlistview. innerhtml = ""; // clear the original content of listview 8 // If the returned record of the server is blank 9 if (listurl. length = 0) {10 $ ("# emrgallery "). append ('<H4> prompt: no data for the current date </H4>'); 11 return; 12} 13 var tempnum = 1; 14 for (VAR I = listurl. length-1; I> = 0; I --) {15 $ ("# emrlistview "). append ('<li> <a href = "#" data-transition = "Fade">
In general, it is not very complicated. It is the string data serialized in JSON in the background control using jquery asynchronous requests at the front end. After successful requests, the JSON characters are deserialized into JS objects and displayed in HTML,