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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:12:00+00:00 2026-06-11T00:12:00+00:00

My code makes an ajax call: $.ajax({ url: /Controller/EmailUserKeys, dataType: ‘json’, success: function ()

  • 0

My code makes an ajax call:

$.ajax({
    url: "/Controller/EmailUserKeys",
    dataType: 'json',
    success: function () {
        alert('success');
    },
    error: function () {
        alert('error');
    }
});

It calls an action in my controller which returns some JSON:

public JsonResult EmailUserKeys(string UserId)
{
    ...
    return Json(new { success = true });
}

My problem is that the ajax error function is called and not the ajax success function.

Why?

PS. If my action returns “return null;”, the ajax success function is called.

  • 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-11T00:12:02+00:00Added an answer on June 11, 2026 at 12:12 am

    You must allow GET which is disabled by default when returning JSON results:

    public JsonResult EmailUserKeys(string UserId)
    {
        ...
        return Json(new { success = true }, JsonRequestBehavior.AllowGet);
    }
    

    or use a POST request:

    $.ajax({
        url: "/Controller/EmailUserKeys",
        type: "POST",
        dataType: 'json',
        data: { userId: 'some user id' },
        success: function () {
            alert('success');
        },
        error: function () {
            alert('error');
        }
    });
    

    Also never hardcode the url to your controller action as you did. Always use url helpers when dealing with urls in an ASP.NET MVC application:

    url: "@Url.Action("EmailUserKeys", "Controller")",
    

    And here’s a piece of advice: use a javascript debugging tool such as FireBug if you are doing any web development. Among with other useful things it allows you to inspect AJAX requests. If you had used it you would have seen the response sent from the server which would have looked like this:

    This request has been blocked because sensitive information could be
    disclosed to third party web sites when this is used in a GET request.
    To allow GET requests, set JsonRequestBehavior to AllowGet.

    And you wouldn’t need to come to StackOverflow and ask this question as you would have already known the answer.

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

Sidebar

Related Questions

I'm having a problem. I have this code: setInterval(function() { $.ajax({ url: url, success:
I have code that makes an AJAX call to an MVC controller method and
I have the following code: $.ajax({ type: POST, url: url, data: sendable, dataType: json,
I have the following code to make a jsonp call. var contacts; $.ajax({ url:
I have this function that makes an ajax call. I'm describing the problem in
I am making this ajax call: $.ajax({ url: /test/whatever, type: 'post', contentType: 'application/json' data:
Below code makes form to be submitted without html5 validation... $j(document).on(click, #client_entry_add, function(event){ ajax_submit();});
I'm running a weird issue here. I have code that makes jquery ajax calls
Hi I have a function that makes ajax calls once an element is clicked.
So, I created an object which makes an AJAX call to populate its properties

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.