Home > Enterprise >  Not hitting Success in Ajax
Not hitting Success in Ajax

Time:08-10

hitting controller and returning data while debugging but in js>>Ajax call>>success is not hitting

repository

 public FGMOQMapping GetFGMOQMappingAutoSuggest(long loginId)
        {
            FGMOQMapping fGMOQMapping = new FGMOQMapping();
            DynamicParameters parameters = new DynamicParameters();
            parameters.Add("LoginId", loginId);

            using (var multi = con.QueryMultiple("usp_FGMOQMapping_GetList_AutoSuggest", parameters, commandType: CommandType.StoredProcedure)) {
                fGMOQMapping.FGList=multi.Read<FGMOQMapping>().ToList();
                fGMOQMapping.SFGList = multi.Read<FGMOQMapping>().ToList();
            }
                return fGMOQMapping;
        }

controller

 public JsonResult NPDAutoSuggest()
        {
            NPD npdObject = new NPD();
            //npdObject.FGList = _purchaseOrderRepository.GetFGMOQMappingList(0, Convert.ToInt64(Session["UserId"]));
            FGMOQMapping fGMOQMapping = new FGMOQMapping();
            fGMOQMapping= _purchaseOrderRepository.GetFGMOQMappingAutoSuggest(Convert.ToInt64(Session["UserId"]));
            npdObject.FGList = fGMOQMapping.FGList;
            npdObject.SFGList = fGMOQMapping.SFGList;
            npdObject.PlantList = _plantRepository.GetPlantList(0, "", "", Convert.ToInt64(Session["UserId"]));
            var Jsondata = JsonConvert.SerializeObject(npdObject);
            return Json(Jsondata, JsonRequestBehavior.AllowGet);
        }

ajax , js

$.ajax({
        
        url: ROOT   "PurchaseOrder/NPDAutoSuggest",
        type: 'POST',
        datatype:'JSON',
        success: function (result) {
            
            AutoData = JSON.parse(result);
        },
        error: function (result) {
            console.log(result);
            alert("not");
        }
    });

ajax is hitting error block, please help me out to solve this

CodePudding user response:

You create an anonymous object to send to the ajax success method. like this

return Json(new { data = Jsondata }, JsonRequestBehavior.AllowGet);

And in ajax get this anonymous object

success: function (result) {
    AutoData = JSON.parse(result.data); //Get data object
}

CodePudding user response:

hello everything was fine here . but json limit exceeded so i used return in different way in controller (if You have large amount of data we may get this issue so use this return kind)

public JsonResult NPDAutoSuggest()
        {
            NPD npdObject = new NPD();
            FGMOQMapping fGMOQMapping = new FGMOQMapping();
            fGMOQMapping = _purchaseOrderRepository.GetFGMOQMappingAutoSuggest(Convert.ToInt64(Session["UserId"]));
            npdObject.FGList = fGMOQMapping.FGList;
            npdObject.SFGList = fGMOQMapping.SFGList;
            npdObject.PlantList = _plantRepository.GetPlantList(0, "", "", Convert.ToInt64(Session["UserId"]));
            return new JsonResult
            {
                Data = npdObject,
                MaxJsonLength = Int32.MaxValue
            };
        }

  • Related