PDA

View Full Version : Json return from Asp.Net WebApi



rossano
19 Sep 2019, 6:18 AM
Hi I installed the application tutorial Modern-Tunes and all works fine.

When I call the ITunes service with


proxy: {
type: 'jsonp',
url: 'https://itunes.apple.com/us/rss/topmusicvideos/limit=4/json',
reader: {
type: 'json',
rootProperty: 'feed.entry'
}
}

and analize the response with chrome developers tools, I see this Response:

Ext.data.JsonP.callback1({"feed":{"author":{"name":{"label" .......... etc etc })

Here the call to ITunes service:
https://itunes.apple.com/us/rss/topmusicvideos/limit=4/json?_dc=1568899078169&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback1

All works fine (the grids present in Modern-Tune app are correctly populated).


Now I tried to extend the Modern-Tunes application with a new call to my WebApi class with:


proxy: {
type: 'jsonp',
url: 'https://localhost:44393/api/vinileobj',
reader: {
type: 'json'
}
}

to call GET action on my running .Net application.

And here the .Net controller:


public class VinileObjController : ApiController {

public List<Vinile> Get() {
Vinile v1 = new Vinile();
v1.Id = "1";
v1.Title = "Attenti al lupo";
v1.Artist = "Lucio Dalla";

Vinile v2 = new Vinile();
v2.Id = "2";
v2.Title = "Cirano";
v2.Artist = "Francesco Guccini";

List<Vinile> listaVinili = new List<Vinile>();
listaVinili.Add(v1);
listaVinili.Add(v2);

return listaVinili;
}

}

Here the call: https://localhost:44393/api/vinileobj?_dc=1568899078187&page=1&start=0&limit=25&callback=Ext.data.JsonP.callback2

The new call works fine but when I analyze the Response using chrome developers tools I see that:

[{"Id":"1","Title":"Attenti al lupo","Artist":"Lucio Dalla"},{"Id":"2","Title":"Cirano","Artist":"Francesco Guccini"}]

The Response does not contain the callback Ext.data.JsonP.callback2 and I do not understand why!


Can someone help me to understand the problem?

Thanx

evant
19 Sep 2019, 1:59 PM
Roughly related: https://stackoverflow.com/questions/5359224/parsererror-after-jquery-ajax-request-with-jsonp-content-type/5359239#5359239