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 6163621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:51:22+00:00 2026-05-23T21:51:22+00:00

Update My problem was that I used event.preventDefault() instead of return false to hinder

  • 0

Update

My problem was that I used event.preventDefault() instead of return false to hinder the form from posting normally. FF and IE didn’t like that and broke the JS by that line. I removed that and appended return false at the end and this solved the problem. Thanks to Darin Dimitrov for the extensive checklist.

Original question

I’m using ASP.NET MVC3 and jquery ajax to post json-data to the server and receive a response. However, when I’m using Chrome it reads the json-response normally, updating the divs that I want etc. With IE and FF it doesn’t work though. They read just the response and shows only that on the page.

I saw some other threads mentioning to define the mime type as “text/plain”. This changed the previous behavior of prompting the user to download the json-response instead.

This is the javascript for making the post:

 $.ajax({
        url: $("#formRegister").attr("action"),
        type: 'POST',
        data: JSON.stringify(user),
        dataType: 'json',
        contentType: 'application/json, charset=utf-8',
        traditional: true,
        success: function (data) {
            alertMessage(data.Message);

        },
        error: function () {

        }
    });

This is the ActionMethod receiving the call and returning a JsonResponse:

[HttpPost]
    public JsonResult Register(UserRegisterPackage package)
    {
        ClientAlert alert = new ClientAlert();
        if (package.Password != null)
        {       
            //bool success = Removed for simplicity's sake.
            bool success = true;
            if (success)
            {                    
                alert.Message = "Success!";                    
            }
            else
            {                    
                alert.Message = "Failed to register";                    
            }
        }
        else
        {                
            alert.Message = "You need to enter a password!";                
        }
        return Json(alert, "text/plain");
    }

As I said, when the content type is defined as text/plain the browser shows only the response and when it’s not defined it prompts the user to download the json-response instead.

With FF I seem to get an error about:

"event is not defined
event.preventDefault(); "

This could have something to do with the error.. but I need to prevent the form from posting normally. Is this done differently in FF or IE?

Any ideas?

  • 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-23T21:51:23+00:00Added an answer on May 23, 2026 at 9:51 pm

    Things to try:

    1. If this $.ajax call is made inside the .click or .submit handler of some anchor or <form> make sure you return false; at the end in order to cancel the default behavior and leave time for your AJAX request to execute. The attr('action') that you are using leaves me to believe that this is the case.
    2. Remove traditional: true parameter, you are sending a JSON request => it is irrelevant.
    3. Make sure there aren’t some other javascript errors on your page as they might stop js execution and proceed into normal form submission
    4. Remove all text/plain from your server if you intend to return JSON. It’s meaningless to do something like this and it’s definitely not where your problem comes from. Simply use return Json(alert);.

    So if you are AJAXifying a form you don’t even need any JSON requests, simply:

    $('#formRegister').submit(function() {
        $.ajax({
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            success: function (data) {
                alertMessage(data.Message);
            },
            error: function () {
    
            }
        });
        return false;
    });
    

    and if you intend to send JSON requests then your code seems fine, jsu make sure there aren’t some other JS errors.

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

Sidebar

Related Questions

The problem: I often have to update two or more repositories: One for the
I have a very weird problem: sometimes when I call nHibernate update to an
I am having virtually the same problem as this: C# Update combobox bound to
I've encountered a problem with my Netbeans 6.1 IDE. After an unsuccessful update, Netbeans
Today we faced a quite simple problem that were made even simpler by the
ExtendedDateChooser class is great solution for simple event calendar used in my flex project.
I am new to JavaScript and didn't arrive to find a working script that
I am trying to establish a PIM listener that will update a MainScreen where
Update: Solved, with code I got it working, see my answer below for the
Update: Check out this follow-up question: Gem Update on Windows - is it broken?

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.