I am trying to POST data to an Asp.Net Web API on another one of my domains. I need to support IE9/8 so CORS won’t cut it. When I make a call like this:
$.ajax({
type: "GET",
url: "http://www.myotherdomain.com/account",
data: "{firstName:'John', lastName:'Smith'}",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function(msg) {
console.log(msg);
},
error: function(x, e) {
console.log(x);
}
});
it makes a GET request to:
http://www.myotherdomain.com/account?
callback=jQuery18008523724081460387_1347223856707&
{firstName:'John',%20lastName:'Smith'}&
_=1347223856725
I’ve implemented this JSONP Formatter for ASP.NET Web API and my server responds with a properly formatted JSONP response. I don’t understand how to register a route to consume an account object.
config.Routes.MapHttpRoute(
name: "Account",
routeTemplate: "account",
defaults: new { controller = "account", account = RouteParameter.Optional }
);
How do I deserialize an object from a querystring parameter without name?
Instead of using JSON you could send the parameters as query string values. Let’s suppose that you have the following model:
and the following API controller:
which could be consumed like that: