Ajax error message

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
HellO!
I have some ajax on client side. It looks like

  $.ajax({
                                        cache: false,
                                        type: "POST",
                                        url: "@(Url.Action("AddShipmentRestriction", "ShipmentRestrictions"))",
                                        data: postData,
                                        success: function(data) {
                                            var grid = $("#newsletter-subscriptions-grid").data('kendoGrid');
                                            grid.dataSource.read();
                                        },
                                        error: function(xhr, ajaxOptions, thrownError) {
                                            alert('Failed to add record.');
                                        }
                                    });


And on a method on controller i have

f (r != null)
            {
                return Json(new { Result = false }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                    var shipmentRestrictionRecord = new ShipmentRestrictionsRecord()
                    {
                        ShipmentMethodId = shippingMethod.Id,
                        StateProvinceId = stateproviceId
                    };

                    _shipmentRestrictionsService.Add(shipmentRestrictionRecord);
                }

                return Json(new { Result = true }, JsonRequestBehavior.AllowGet);
            }


So true result reread my grid and its fine. But on false i want to see this notification from ajax but I don't!
Could u please tell me why?
7 years ago
art_MOO wrote:
HellO!
I have some ajax on client side. It looks like

  $.ajax({
                                        cache: false,
                                        type: "POST",
                                        url: "@(Url.Action("AddShipmentRestriction", "ShipmentRestrictions"))",
                                        data: postData,
                                        success: function(data) {
                                            var grid = $("#newsletter-subscriptions-grid").data('kendoGrid');
                                            grid.dataSource.read();
                                        },
                                        error: function(xhr, ajaxOptions, thrownError) {
                                            alert('Failed to add record.');
                                        }
                                    });


And on a method on controller i have

f (r != null)
            {
                return Json(new { Result = false }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                    var shipmentRestrictionRecord = new ShipmentRestrictionsRecord()
                    {
                        ShipmentMethodId = shippingMethod.Id,
                        StateProvinceId = stateproviceId
                    };

                    _shipmentRestrictionsService.Add(shipmentRestrictionRecord);
                }

                return Json(new { Result = true }, JsonRequestBehavior.AllowGet);
            }


So true result reread my grid and its fine. But on false i want to see this notification from ajax but I don't!
Could u please tell me why?


You should handle it on success function


  $.ajax({
                                        cache: false,
                                        type: "POST",
                                        url: "@(Url.Action("AddShipmentRestriction", "ShipmentRestrictions"))",
                                        data: postData,
                                        success: function(data) {
                                            
                                            // do something here depending on true or false

                                            var grid = $("#newsletter-subscriptions-grid").data('kendoGrid');
                                            grid.dataSource.read();
                                        },
                                        error: function(xhr, ajaxOptions, thrownError) {
                                            alert('Failed to add record.');
                                        }
                                    });
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.