Asht T

Asht T

  • 778
  • 866
  • 14.2k

Ajax call after pass parameter error occured

Apr 20 2022 9:20 AM

After passing parameter  ajax call 500 Internal Server Occured

In MVC Using Ajax call   Without passing parameter data getting successfullly but after pass parameter ajax call 500 Internal Server Occured

Not Working Code :

var AcadYear = $('#ddlAcadYear option:selected').val();
  $.ajax({
      type: "POST",
      url: '@Url.Action("GetReportDetails", "RptStudentList")',
      data: "{'AcadYear':'" + AcadYear + "'}",  
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: OnSuccess,
      failure: function (response) {
          alert(response.d);
      },
      error: function (response) {
          alert(response.d);
      }
  });
function OnSuccess(response) {

    $("#tblShowDetails").DataTable(
  {
      bRetrieve: true
  })
    $("#tblShowDetails").DataTable(
    {
        "scrollY": 500,
        "scrollX": true,
        destroy: true,
        bSort: true,
        bPaginate: true,
        dom: 'Bfrtip',
        data: response,
        columns: [{ 'data': 'str1' },
                 { 'data': 'str2' },
                 { 'data': 'str3' },
                 { 'data': 'str4' },
                 { 'data': 'str5' },
        ]

    });

};

Working  Code :

var AcadYear = $('#ddlAcadYear option:selected').val();
$.ajax({
    type: "POST",
    url: '@Url.Action("GetReportDetails", "RptStudentList")',
    data: "{}",  
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    failure: function (response) {
        alert(response.d);
    },
    error: function (response) {
        alert(response.d);
    }
});
function OnSuccess(response) {

    $("#tblShowDetails").DataTable(
  {
      bRetrieve: true
  })
    $("#tblShowDetails").DataTable(
    {
        "scrollY": 500,
        "scrollX": true,
        destroy: true,
        bSort: true,
        bPaginate: true,
        dom: 'Bfrtip',
        data: response,
        columns: [{ 'data': 'str1' },
                 { 'data': 'str2' },
                 { 'data': 'str3' },
                 { 'data': 'str4' },
                 { 'data': 'str5' },
        ]

    });

};

 


Answers (3)