Copy Code code as follows:
Grammar:
$ (function () {
The var callback = function (r) {//R represents the data returned by the background data.
}
$.get ("", callback); The path to write the method inside quotation marks
});
This allows the backend method to get the data displayed in front of the HTML.
Here are some of the JS and backstage methods written in the work:
Js:
Copy Code code as follows:
$ (function () {
var callback = function (r) {
var data = "<marquee width= ' 853" height= ' 250px; ' scrollamount= ' 2 ' scrolldelay= ' 4 ' direction= ' Up ' behavior= ' Loop ' Onmouseout= ' This.start () ' onmouseover= ' this.stop () ' ><ul> '
var data2 = "<div class= ' marquee_div ' ><span onclick= ' closelist () ' ></span> discount list </div> ';
for (var i = 0; i < r.length; i++) {
Data + + ("<li><label>" + r[i].time + "</label><span>" + r[i]. CustomerName + "</span> application to obtain a successful purchase year service fee 90 percent discount, congratulations!</li>");
}
Data + = "</marquee></ul>";
$ ("#01_companys"). HTML (data);
var t_data2 = "";
for (var i = 0; i < r.length i++) {
if (i% 2 = 0) {
T_data2 + = "</div><div class= ' ListTitle ' >";
}
T_data2 + = "<div style=" width:49%; height:40px; line-height:40px; Float:left ' > ' + (i + 1) + "." + r[r.length-i-1]. CustomerName + "</div>";
}
$ ("#01_list"). HTML (data2 + (t_data2.length > 0 t_data2.substr (6, t_data2.length-6): "") + "</div>");
}
$.get ("/activity/trycompany", callback);
});
Background code (MVC4):
Copy Code code as follows:
Public ActionResult Trycompany ()
{
String customertype = Res.CustomerType.TestCustomer.ToString ();
ilist<customers> vlist = o_res.gethtmlcustomers (1, Out Pcount, (a => A.customertype = = CustomerType));
var list = Vlist. ToList (). ConvertAll (S =>
{
Return to new {s.customername, time = S.adddate.hasvalue? s.adddate.value.tostring ("Mm-dd hh:mm"): ""};
});
return Json (list, jsonrequestbehavior.allowget);
}
The background gets a LIST,JQ call, traverses, and then displays at the front end.
A very simple example, there must be a simpler way, and so on later to dig.