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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:09:43+00:00 2026-06-11T20:09:43+00:00

Possible Duplicate: Ajax cross domain call I have Asp.Net Controller methods which return JSON

  • 0

Possible Duplicate:
Ajax cross domain call

I have Asp.Net Controller methods which return JSON response. However I am unable to call it from a different domain using Jquery’s $.getJSON(...){}

Quick googling suggests that JSONP must be used. Question is what is the difference between JSON and JSONP? Is that just another new term? And if JSONP is working why I can’t I make JSON work? Is there any way to not use these fancy JSONP and use plain old JSON because I am afraid of any changes to my server side code.

  • 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-11T20:09:44+00:00Added an answer on June 11, 2026 at 8:09 pm

    You cannot make cross domain AJAX calls using JSON. You need to use JSONP. So instead of returning a regular JsonResult from your controller action write a custom action result that will wrap the JSON in a callback that is passed as parameter:

    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 then have your controller action return this custom action result:

    public ActionResult SomeAction()
    {
        var result = new[]
        {
            new { Id = 1, Name = "item 1" },
            new { Id = 2, Name = "item 2" },
            new { Id = 3, Name = "item 3" },
        };
        return new JsonpResult(balances);
    }
    

    Now you could consume this action cross domain:

    var url = "http://example.com/SomeController/SomeAction/";
    $.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

Possible Duplicate: How to: Back button support “Ajax” I have a ASP.NET MVC implementation
Possible Duplicate: jQuery: Return data after ajax call success I have the following function
Possible Duplicate: jQuery: Return data after ajax call success I wrote a script which
Possible Duplicate: JQuery ajax cross domain I need to load content from another websites
Possible Duplicate: return AJAX callback return I have made a JQuery code using AJAX,
Possible Duplicate: jQuery won't parse my JSON from AJAX query So I have parsed
Possible Duplicate: Why is cross-domain Ajax a security concern? I'm having a huge issue
Possible Duplicate: jQuery: Return data after ajax call success jQuery AJAX: return value on
Possible Duplicate: submit form does not stop in jquery ajax call I have a
Possible Duplicate: jquery (ajax) redirect to another domain I have the jQuery Ajax request

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.