jquery uses Ajax to invoke background method instances _jquery

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.