Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
AJAX Callback Not Showing Success Message - ASP.NET MVC C#

I have some AJAX code in my JavaScript which is not showing any success or failure alert.

  function AttemptHouseViewingAppointment(house) {

    var imgOfHouse = $(house).attr("value");
    $.ajax({
        type: "POST",
        url: '@Url.Action("AttemptHouseViewingAppointment", "Viewing")',
        dataType: "json",
        data: ({
            userId: @Model.UserId,
            appointmentKey: '@Model.Key',
            chosenHouse: imgOfHouse 
        }),
        success: function (data) {
            alert(data);
            if (data.success) {
                alert(data.message);
            } else { alert(data.Message) }
        },
        error: function (xhr) {
            alert(xhr.responseText);
        }
    });

};

The above function is called when I click an image on the screen. This part works fine as I have set a breakpoint on my ASP controller and I can see the relevant action being called. C# code below:

    public ActionResult AttemptHouseViewingAppointment(int userId, string appointmentKey, int chosenHouse)
    {
        string selecteHouseName = $"./house-code-icons/{chosenHouse}.png";

        var house = 
            _ctx.houses.Where(x => x.HouseID == userId && x.Icon == chosenHouse)
                        .FirstOrDefault() ?? null;

        if(house != null)
        {
            var member = _ctx.User.FirstOrDefault(x => x.Id.Equals(userId));

            _ctx.Appointments.Add(new ViewingModel
            {
                House = chosenHouse,
                UserId = userId
            });

            _ctx.SaveChanges();

            return Json(new { success = true, message = "Appointment Confirmed!" });
        }
        else
        {
            return Json(new { success = false, message = "Sorry, a booking has already been made!" });
        }
    }

Even though, the return Json lines are being hit and returned to the page, there is no alert popup on my page to let user know if success or not. Please let me know if any questions.

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add the done function to the end of Ajax

$.ajax({
    .
    .
    .
}).done(function( response ) {
   alert(response);
    ...
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!