/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/// <summary> /// Return list of anonymous product highlight objects. /// </summary> /// <param name="productID"></param> /// <returns></returns> [WebMethod] public static List<object> GetHighlights(int productID) { return (from h in context.ProductHighlights where h.ProductID == productID select new { h.Description, h.DisplaySequence }).ToList<object>(); } //jquery to send request: $.ajax({ type: "POST", url: "/Admin/Products/Overview.aspx/GetHighlightsf", data: "{productID: '" + $('#hfProductID').val() + "' }", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg.d == "false") alert('There was an error retrieving product highlights via ajax.'); var highlights = msg.d; $.each(highlights, function (index, highlight) { RenderHighlight(highlight); }); }, failure: function (msg) { alert('Error: ' + msg); } }); //the function that renders the new table row: function RenderHighlight(highlight) { highlightRow = '<tr><td><input type="text" name="highlight" value="' + highlight.Description + '" class="text-input large-input"/></td><td class="tools"><a href="#" class="add">Add</a><a href="#" class="remove" rel="">Remove</a></td></tr>'; $('#highlights tbody:last').append(highlightRow); if ($('a.add').size() == 1) { $('a.remove').hide(); } }