01/10/2018, 00:02

Why my ajax post alway return error ? Please , i search google but i don't fix it

This is jquery for add item button. I use post method to send data to controller.

$("#AddItem").click(function () {
            var listCheck = $("input.tableflat:checkbox:checked");

               if (listCheck.length > 0) {
                    listCheck.each(function () {
                        var campid = "Campaign A";
                        var itemcode = $(this).parents('.trParent').children('td').children('#ItemCode').val();
                        var itemname = $(this).parents('.trParent').children('td').children('#ItemName').val();
                        var qtyorder = $(this).parents('.trParent').children('td').children('#Order').val();
                        var qtyhandout = $(this).parents('.trParent').children('td').children('#Handout').val();

                        lstPromotionItems.push({
                            Campaign: campid,
                            ItemCode: itemcode,
                            ItemName: itemname,
                            QtyOrder: qtyorder,
                            QtyHandout: qtyhandout
                        });

                    });
               }
               if (lstPromotionItems.length > 0) {
                   $.each(lstPromotionItems, function () {
                       //var data = JSON.parse(lstPromotionItems);
                       $.ajax({
                           url: '@Url.Action("PromontionItemsPartial", "Promote")',
                           dataType: 'json',
                           type: 'POST',
                           contentType: "application/json; charset=utf-8",
                           data: JSON.stringify(lstPromotionItems),
                           //cache: false,
                       })
                       .success(function (data) {
                           $("#PromontionItems").html(data);
                       })
                       .error(function (error) {
                           alert(JSON.stringify(error))
                       })
                   });


               }
            })

And this is my controller for jquery. I use partial view action to show data.

public PartialViewResult PromontionItemsPartial(List<PROMOTIONITEM> LstPromoItem)
        {
            return PartialView(LstPromoItem);
        }

i don’t know why it return error. i try to JsonResult but i fail…!. Show error, i see my data in partial view return.

public JsonResult PromontionItemsPartial(List<PROMOTIONITEM> LstPromoItem)
        {
            //var lst = PromontionItemsJSON(LstPromoItem);
            return Json(new { LstPromoItem });
        }
Bài liên quan
0