1

Hi all why does data normall webapi return data in an ajax call where as odata returns data.d.results in ajax call..what is the difference between them

 normall webapi call using ajax

   $.ajax({
        url: url,
        jsonp: '$callback',
        dataType: 'jsonp',
        success: function (data) { 
       //data is returned as data when an webapi is called               
                PreReqisites.varResult = data;
                  }                    
             });

but when an odata service is called

      $.ajax({
        url: url,
        jsonp: '$callback',
        dataType: 'jsonp',
        success: function (data) { 
       //data is returned as data.d.results when an webapi is called               
                PreReqisites.varResult = data.d.results;
                  }                    
             });

why is that data returned in these ways in odata in webapi can any one tell me pros and cons of it

tereško
  • 58,060
  • 25
  • 98
  • 150
  • Possible duplicate http://stackoverflow.com/questions/739859/returning-html-from-json-webservice-what-is-the-d – Brad M Feb 26 '13 at 18:15

1 Answers1

1

why is that data returned in these ways in odata in webapi can any one tell me pros and cons of it

each webservice typically has defined its own data structure. Its up to you to figure out what the structure is in order to handle it correctly.

using a console like firebug, inspect the return data for each type and see the differences for yourself.

Once you know what data structure to expect, code your namespaces accordingly (i.e. some.data.key)

Kristian
  • 21,204
  • 19
  • 101
  • 176