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

  • SEARCH
  • Home
  • 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 7935475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:56:02+00:00 2026-06-03T21:56:02+00:00

I have a problem when developing a single page web app. When jQuery send

  • 0

I have a problem when developing a single page web app.

When jQuery send json to HTTPPOST action:

$('#user_dialog .create').click(function () {
                            var user = getInfoUser();
                            $.ajax({
                                url: '@Url.Action("Create", "User")',
                                async: false,
                                type: 'POST',
                                data: JSON.stringify(user),
                                datatype: 'json',
                                contentType: 'application/json;charset=utf-8',
                                success: function (data) {
                                    $('#user_dialog').dialog("close");
                                }
                            });
                        });

My HTTPPOST action in controller will handle the request

[HttpPost]
  public String Create(UserAddViewModel model)
        {
            try
            {
                // TODO: Add insert logic here

                return JsonConvert.SerializeObject(true);
            }
            catch
            {
                return JsonConvert.SerializeObject(false);
            }
        }

And my jQuery success callback function will be fired and data ‘true’ will be received.

But the problem now is after this, the page will be redirect to /User/Create view page

I don’t want it redirect to the page, i just want to handle the UI by my jQuery code.

Is that because it is HTTPPOST action?

What is the actual reason and how to fix it?

  • 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-06-03T21:56:04+00:00Added an answer on June 3, 2026 at 9:56 pm

    Presumably, the thing you’re clicking is a URL. You’re not preventing the default event (loading the url) from occuring in your click event

    $('#user_dialog .create').click(function (event) {
        event.preventDefault();
        //rest of function
    

    Whenever a click event finishes, the default event (loading a URL if it’s a link, submitting a form if it’s a submit button, toggling a checkbox, etc.) will occur next. In order to prevent this you must do it explicitly either using preventDefault() or by returning false. See http://api.jquery.com/event.preventDefault/ for the documentation.

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

Sidebar

Related Questions

I have a small problem developing/optimizing a web page. I know it is good
I'm developing small FTP upload app. for mac (10.6 if it matters) Have problem
I have a strange problem in an iPhone app I'm developing. I want my
i have a problem i am developing an asp.net mvc project. Website is in
I'm developing an Eclipse plug-in and I have a problem which is reproduced here:
I have a problem linking an application for an embedded target. I'm developing on
I have this problem and it's drivin' me nuts! So I am developing my
I am developing an xbap application and have run into a problem with users
Currently developing a PHP framework and have ran into my first problem. I need
I'm hoping people have some ideas to help solve this problem. I am developing

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.