0

This is my ASP.NET code -


if (appointmentScheduledStartDate.HasValue)
{
   var appointmentDate = appointmentScheduledStartDate.Value.Date.AddDays(1);
   if(appointmentDate < currentDateAndTime)
   {
      throw new Exception("Link Expired");
   }
}

And this is my jQuery.


function logChekInData(entityName, recordId, userId, lat, lon) {
        

x.innerHTML = "Please wait...";
            $.ajax({
                type: "POST",
                dataType: "Json",
                contentType: "application/json; charset=utf-8",
                url: '@Url.Action("LogCheckIn", "InvestigatorCheckIn")',
                data: JSON.stringify({
                    'entityName': entityName,
                    "recordId": recordId,
                    "userId": userId,
                    "lat": lat,
                    "lon": lon
                }),
                async: false,
                success: function (data) {
                    x.innerHTML = "Successfully tracked your location.";
                },
                error: function (xhr) {
                    x.innerHTML = xhr.responseText.Message;
                    //x.innerHTML = "Error occured. Please try later.";
                   //alert(xhr.responseText);
                }
            });
    }

Let me know how can I get the exception message via jQuery.ajax? I'm getting undefined message every time. How can I solve this ?

Nayeem Rahman
  • 29
  • 1
  • 7
  • Hello there, you can check this link to get some sort of advice on how to tackle your problem.https://stackoverflow.com/questions/27246598/how-to-call-error-function-in-ajax-with-c-sharp-mvc4 It would be also nice if you could post the rest of your C# code above. – Oris Sin Jan 05 '23 at 10:00
  • I dont want to return JSON rather throw exception. – Nayeem Rahman Jan 05 '23 at 10:14

0 Answers0