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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:24:13+00:00 2026-05-25T18:24:13+00:00

I have an MVC 3 web app that has an Action which I need

  • 0

I have an MVC 3 web app that has an Action which I need to access from a webform app via javascript.

My action returns a Json result, which I have checked works just fine. However, when accessing it with javascript from another application, I can see it reaching my action, doing all the work, returning my data, but the jquery function then gives me an error 200 and no data.

Example:
My MVC Action:

public ActionResult GetData(int categoryId)
{
   var listofSeries = new List<string>
               {
                   "foo1",
                   "foo2",
                   "foo3"
               };
   return Json(listofSeries, JsonRequestBehavior.AllowGet);
}

This returns me: ["foo1","foo2","foo3"]

Normally, my javascript function is used to query a database and get data back for a Highcharts chart but I have the same issue with this kind of example.

<script type="text/javascript">
    $(document).ready(function () {
        var foo = getData(9);
    });

    function getData(categoryId) {
            var results;

            $.ajax({
                type: 'POST',
                url: 'http://localhost:xxxx/Home/GetData',
                //contentType: "application/json; charset=utf-8;",
                async: false,
                data: { "categoryId": categoryId },
                dataType: "json",
                success: function (data) {
                    console.log("results: " + data);
                    results = data;
                }
            });

            return results;
        }
</script>

With this I get:

http://localhost:63418/Home/GetData?categoryId=9 200 OK
results: null

If I add the contentType, I can’t even see the function running in the firebug console, all I see is results: null. When I remove it I do but I get the error above.

I’ve been told it might not be doable because of “Cross-site scripting”. And to instead have my javascript function call a webservice (or handler but I haven’t quite figured out how to make one of those yet) that will then call my action, return my data to the service who then returns the data to the javascript.

But now I’m getting a 415 Unsupported Media Type error message when trying to connect to my webservice.

My IWebService.cs:

[ServiceContract]
    public interface IWebService
    {
        [OperationContract]
        [WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        void GetData(int mileId);
    }

My WebService.svc:

public void GetData(int categoryId)
{
    string url = "http://localhost:63418/Home/GetWoWData?categoryId=" + categoryId;
    WebRequest wr = WebRequest.Create(url);
    WebResponse response = wr.GetResponse();
}

I’m not returning anything yet, it won’t even go in this function. Giving me the 415 error message.

If I change the contentType to “text/xml” I get an error 400.

I would really like to have this work without using the webservice, and figure why I get an error 200 OK when I can see the action running, but if that’s not possible, any idea why the webservice isn’t working?

Thanks.

  • 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-25T18:24:14+00:00Added an answer on May 25, 2026 at 6:24 pm
            string url = "http://localhost:63418/Home/GetWoWData?categoryId=" + categoryId;
            WebRequest wr = WebRequest.Create(url);
            wr.Credentials = CredentialCache.DefaultNetworkCredentials; // uses current windows user
            var response = (HttpWebResponse)wr.GetResponse();
    

    I only just remembered I had this post and found the solution a while ago. It was solved by adding the credentials (in my case the current windows user) and getting the response as an HttpWebResponse.

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

Sidebar

Related Questions

I have an asp.net mvc web app that has controllers with role attributes on
I have an ASP.NET MVC web app which has a really basic subscription system
I have an asp.net mvc app that is built to run as standard web
I have an object which contains models for my ASP.NET MVC web app. The
We have an ASP.NET MVC web app which allows users to publish messages onto
i have an asp.net mvc app that has a form that uploads a file.
I have an MVC web app running in azure that serves up large files
I have an MVC 2 app that has a System.Timers.Timer object starting up during
We have an MVC web app that uses FormsAuthentication and also stores a couple
I have an iPad app that submits orders to an ASP.NET MVC web site

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.