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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:15:04+00:00 2026-06-09T02:15:04+00:00

I have some data Foo that I want to pass from the browser to

  • 0

I have some data “Foo” that I want to pass from the browser to the server and retrieve predicted statistics based on the information contained within foo.

$.ajax({
      type: 'GET',
      url: "/api/predictedStats/",
      data: "foo=" + ko.toJSON(foo, fooProperties),
      contentType: 'application/json; charset=utf-8',
      dataType: 'json',
      success: function(data) {
        return _this.viewModel.setPredictedStats(data);
      },
      error: function(jqXHR, statusText, errorText) {
        return _this.viewModel.setErrorValues(jqXHR, errorText);
      }
    });

I created a predicted stats controller and get method taking an argument of Foo.

public class PredictedStatsController : ApiController
{
    public PredictedStats Get(Foo foo)
    {
        return statsService.GetPredictedStats(foo);
    }
}

Sticking a breakpoint on the Get method I see the Foo object is always null. There are no errors thrown from the webapi trace logging just the following lines.

WEBAPI: opr[FormatterParameterBinding] opn[ExecuteBindingAsync] msg[Binding parameter 'foo'] status[0]  
WEBAPI: opr[JsonMediaTypeFormatter] opn[ReadFromStreamAsync] msg[Type='foo', content-type='application/json; charset=utf-8'] status[0]  
WEBAPI: opr[JsonMediaTypeFormatter] opn[ReadFromStreamAsync] msg[Value read='null'] status[0]   

I’ve no problem sending the data via a post to the Foo controller to create the Foo object on the server so I can say there’s nothing wrong with the json created clientside.

Looking in fiddler the resulting Get looks like the following where jsondata is the object foo.

GET /api/predictedStats?foo={jsondata} HTTP/1.1

Is this even possible or am I going about this all wrong?

Thanks
Neil


EDIT:
I feel like I almost got this working with the following

public PredictedStats Get([FromUri]Foo foo)
{
    return statsService.GetPredictedStats(foo);
}

The object foo was coming back fine but no properties of Foo were being populated properly.


In the mean time I’ve resorted to using a POST with near identical data just dropping the “foo=” and this is working just fine.

I’m not sure whether the POST or the GET should be used in this case but that would be interesting to know.


I also found this http://bugs.jquery.com/ticket/8961 which seems to suggest you can’t attach a body to a GET request with jquery so POST is probably the only sensible option

  • 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-09T02:15:05+00:00Added an answer on June 9, 2026 at 2:15 am

    You almost got there 🙂

    When you use [FromUri] (which you have to use for ‘complex’ objects because by default Web API doesn’t ‘bind’ complex objects, it’s always looking to deserialize them from the body) you don’t need to pass param= in the Uri – you just pass the members of the value as query string parameters. That is 'member1=value&member2=value' – where member1 and member2 are members of the Foo.

    Note there is no ‘bug’ in jQuery – while the HTTP spec doesn’t prohibit a request body, it’s likely that the browser does (and if that’s the case, the jQuery can’t send it), and it’s more than likely that a server will never read it anyway. It’s just not accepted practise. It also has interesting issues with caching potentially, as well, in that a browser won’t cache a POST, PUT, DELETE etc, but will cache a GET if the response headers don’t prohibit it – that could have serious side effects for a client application. I recommend you look at this SO: HTTP GET with request body for more information and some useful links on this subject.

    Equally, when using jQuery – you don’t need to convert the object to JSON either – just pass the javascript object in the data member of the options and jQuery turns it into the correct format.

    Or should that be, Web API understands the format the jQuery passes it as.

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

Sidebar

Related Questions

In my project I have some objects that I show from a server, lets
I have some data from log files and would like to group entries by
I have some data that is stored in a TIMESTAMP(6) WITH TIMEZONE column in
I have some data which i need to make some statistics. I need to
I have some data that won't printf.... echo works, but not printf There is
I have some data that I would like to visualize. Each byte of the
I have some code that I want to refactor. I have lots of methods
Suppose that I have two data types Foo and Bar. Foo has fields x
I have an R data frame containing a factor that I want to expand
I have some XML that looks like <?xml version=1.0?> <root> <![CDATA[ > foo ]]>

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.