In my Web Api project I have a Get method which returns data from my datasource:
[WebGet(UriTemplate = "")]
public IQueryable<Product> Get()
{
var products = _db.Products;
return products.AsQueryable();
}
When I view this in the browser with the test client, when I specify to return as JSON it works fine and JSON is returned.
On my other client, I have to make a JSONP due to my API being hosted on same domain (For development only), but the data I receive back from my JSON request is XML, how can I make it return as JSON? Below is my code to make the request:
$.ajax({
crossDomain: true,
dataType: "jsonp",
url: "http://localhost:9000/api/products",
contentType: 'application/json; charset=utf-8',
type: "get",
success: function (data) {
console.log(data);
}
});