Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3634818
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:49:35+00:00 2026-05-19T00:49:35+00:00

Okay please help, I’ve been frustrated with this issue. I need to either set

  • 0

Okay please help, I’ve been frustrated with this issue.

I need to either set an error value or perform a redirect when a user hits the submit button. (its a standard login form). I need to do it with ajax.

I think its almost working, however when the user clicks submit the page just displays:
{“redirect”:”/Home/Index”}

or
{“error”:”The user name or password provided is incorrect.”}

its not redirecting/displaying the error how I’m intending it to.

some background – the form is a login form, and its placed inside a modal popup dialog.(jqueryui)

Heres my jquery:

$("#submit").click(function () {
            $.post({
                url: "Account/LogOn",
                dataType: "json",
                success: function (data) {
                    if (data.redirect) {
                        // data.redirect contains the string URL to redirect to
                        window.location.href = data.redirect;
                    }
                    else {
                        // data.form contains the HTML for the replacement form
                        $("#error").replaceWith(data.error);
                    }
                }
            });
            return false;
        });

and heres my Action method:

[HttpPost]
    public JsonResult LogOn(LogOnModel model, string returnUrl)
    {
        if (ModelState.IsValid)
        {
            if (MembershipService.ValidateUser(model.UserName, model.Password))
            {
                FormsService.SignIn(model.UserName, model.RememberMe);
                if (Url.IsLocalUrl(returnUrl))
                {
                    return Json(new { redirect = returnUrl });
                }
                else
                {
                    return Json(new { redirect = "/Home/Index" });
                }
            }

        }
        return Json(new { error = "The user name or password provided is incorrect." });
    }

heres is my form:

@using (Html.BeginForm("LogOn", "Account"))
{

    <div>
        <fieldset>
            <legend>Account Information</legend>

            <div class="editor-label">
                @Html.LabelFor(m => m.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(m => m.UserName)
                @Html.ValidationMessageFor(m => m.UserName)
            </div>

            <div class="editor-label">
                @Html.LabelFor(m => m.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(m => m.Password)
                @Html.ValidationMessageFor(m => m.Password)
            </div>

            <div class="editor-label">
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe)
            </div>

            <p>
                <input id="submit" type="submit" value="Log On" />
            </p>
        </fieldset>
    </div>
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:49:36+00:00Added an answer on May 19, 2026 at 12:49 am

    Ouch, the whole $.post()-call is wrong.

    Use this:

    $("#submit").click(function (e) {e.preventDefault();
                $.post( "Account/LogOn",
                        $(this.form).serialize(),
                        function (data) 
                        {
                          if (data.redirect) 
                          {
                            // data.redirect contains the string URL to redirect to
                            window.location.href = data.redirect;
                          }
                          else 
                          {
                            // data.form contains the HTML for the replacement form
                            $("#error").replaceWith(data.error);
                          }
                        },
                        'json'
                );
                return false;
            });
    

    You’ve used the notation of the arguments like expected in $.ajax() , but in $.post() it’s different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so this probably sounds terribly nefarious, but I need such capabilities for my
Okay, so I have this problem with my Fact Table. I need it to
Okay this one has me stumped.. mainly because i have been working on this
Okay so im working on this php image upload system but for some reason
Okay. I know this looks like the typical Why didn't he just Google it
Okay so a continuation from this question , where you experts intro'd me to
Okay, my situation is such: I need to send the contents of a JavaScript
Okay, I might confuse some people who might be able to answer this question,
Okay, I really know this has GOT to be the long way around doing
Okay, I've looked all over the internet for a good solution to get PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.