Description: Oops! The page you are trying to access cannot be found. It may have been removed, renamed, or is currently unavailable. Please double-check the URL for any errors.
Requested URL: /UsersPage/undefined
I've got this AJAX script that is supposed to redirect the user to a specific URL:
$.ajax({
url: '@Url.Action("UsersHome", "UsersPage")',
type: 'POST',
data: {
chosenMood: chosenMood
},
success: function(response) {
// Deal with the successful response
console.log('Success:', response);
// Now let's move the user to the designated URL
window.location.href = response.redirectUrl;
},
error: function(xhr, status, error) {
// Handling any errors that occur
console.error('Error:', error);
// Optionally, display an error message to the user
alert('An error occurred. Please try again later.');
}
});
And here is the controller or destination page:
public ActionResult UsersHome()
{
if (User.Identity.IsAuthenticated)
{
//Session["ChosenMood"] = chosenMood;
var redirectUrl = Url.Action("UsersHome", "UsersPage");
//return Json(new { redirectUrl }, JsonRequestBehavior.AllowGet);
return View();
} else
{
return RedirectToAction("../Home/Index");
}
}