Copy codeThe Code is as follows:
Syntax:
$ (Function (){
Var callback = function (r) {// r indicates the data returned by the background data.
}
$. Get ("", callback); // path of the write method in quotation marks
});
In this way, the data obtained by the background method is displayed on the html front-end.
The following is a js and background method written at work:
Js:
Copy codeThe Code is as follows:
$ (Function (){
Var callback = function (r ){
Var data = "<marquee width = '2017; 'height = '250px; 'rollamount = '2' scrolldelay = '4' ction = 'up' behavior = 'loe' 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> if you have successfully applied for a trial, you will receive a discount on the annual service fee. Congratulations! </Li> ");
}
Data + = "</marquee> </ul> ";
$ ("# 01_companys" pai.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 codeThe Code is as follows:
Public ActionResult TryCompany ()
{
String CustomerType = Res. CustomerType. TestCustomer. ToString ();
IList <Customers> vlist = o_Res.GetHtmlCustomers (1,100, out pCount, (a => a. CustomerType = CustomerType ));
Var list = vlist. ToList (). ConvertAll (s =>
{
Return new {s. CustomerName, time = s. AddDate. HasValue? S. AddDate. Value. ToString ("MM-dd HH: mm "):""};
});
Return Json (list, JsonRequestBehavior. AllowGet );
}
In the background, a list, jq call, traversal, and display on the front end.
For a simple example, there must be a simpler method to mine in the future.