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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:37:14+00:00 2026-06-08T00:37:14+00:00

What seems to be the problem calling the json api from a subdomain? Asp.net

  • 0

What seems to be the problem calling the json api from a subdomain?

Asp.net MVC Action


        [AllowAnonymous]
        [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
        public JsonResult getBalances()
        {
            var balances = new[]
                               {
                                   new {Id = 1, Balance = 3},
                                   new {Id = 2, Balance = 2},
                                   new {Id = 3, Balance = 1}
                               };
            return Json(balances, JsonRequestBehavior.AllowGet);
        }

jquery code


var url = "http://subdomain.mysite.com/getBalances/";

$.getJSON(url + '?callback=?', function (data) {
           alert(data);
        });


But the above script works if I used the twitter api url:


var url = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2";

Here is the request and response headers

The json response is:

[{"Id":1,"Balance":3},{"Id":2,"Balance":2},{"Id":3,"Balance":1}]

  • 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-08T00:37:17+00:00Added an answer on June 8, 2026 at 12:37 am

    I suspect that you are violating the same origin policy. The code works with Twitter because Twitter supports JSONP, whereas your controller action simply returns JSON.

    If you navigate to http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2&callback=abc you wil notice how the JSON response is wrapped with the callback that you provided as query string parameter:

    abc([...])
    

    If you want to achieve the same with your site you should return JSONP. Here’s an example of a custom JSONP action result that you could use:

    public class JsonpResult : ActionResult
    {
        private readonly object _obj;
    
        public JsonpResult(object obj)
        {
            _obj = obj;
        }
    
        public override void ExecuteResult(ControllerContext context)
        {
            var serializer = new JavaScriptSerializer();
            var callbackname = context.HttpContext.Request["callback"];
            var jsonp = string.Format("{0}({1})", callbackname, serializer.Serialize(_obj));
            var response = context.HttpContext.Response;
            response.ContentType = "application/json";
            response.Write(jsonp);
        }
    }
    

    and your controller action becomes:

    [AllowAnonymous]
    [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
    public JsonResult getBalances()
    {
        var balances = new[]
        {
            new { Id = 1, Balance = 3 },
            new { Id = 2, Balance = 2 },
            new { Id = 3, Balance = 1 }
        };
        return new JsonpResult(balances);
    }
    

    and the call:

    var url = "http://subdomain.mysite.com/getBalances/";
    $.getJSON(url + '?callback=?', function (data) {
        alert(data);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling the Firebase REST API from a Node.js process. The problem I'm seeing
I'm trying to get a json serialized object from within an MVC user control
I create a simple MVC Controller action, that takes some json data - then
My app is crashing on Lion when it awakes from sleep. The problem seems
This problem seems very simple to me, but I've been unable to fix it,
The problem seems simple, but I can't seem to find a way to implement
My problem seems similar to Not able to visualize a loaded data , but
My problem seems to be quite simple, but it's not working the intuitive way.
The problem seems very strange. I have a AJAX helper function within a same
My problem seems to be this: heap data allocated by one thread (that later

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.