从RESTAPI检索oData的Ajax调用

从RESTAPI检索oData的Ajax调用,ajax,rest,odata,Ajax,Rest,Odata,我试图使用Ajax从ODataRESTAPI获取数据。Ajax看起来像这样: $(document).ready(function () { $.ajax({ url: "http://localhost:52139/odata/WEB_V_CIVIC_ADDRESS?key=10064450", datatype: 'json', success: function (oResult) {

我试图使用Ajax从ODataRESTAPI获取数据。Ajax看起来像这样:

$(document).ready(function () {
        $.ajax({
            url: "http://localhost:52139/odata/WEB_V_CIVIC_ADDRESS?key=10064450", datatype: 'json',
            success: function (oResult)
            {
                alert("good");
                $('.accountNumber').append(data.accountNumber);
                $('.civicaddress').append(data.civicaddress);
            },
            error: function(data)
            {
                alert('bad');
            }
        });
    });
URL的调用很好,但我总是收到“坏”的警报,因此调用抛出了一个错误。url正在返回:

{“@odata.context”:“$metadata#WEB#V#u CIVIC#ADDRESS/$entity”,“@odata.type”:“#Values.Classes.Entities.AccountAddress”,“accountNumber”:10064450,“rowNumber”:0,“civicaddress”:“123 Fake St”}

那么如何从ajax调用中获取accountNumber和civicaddress呢


谢谢。

如果有人感兴趣,解决方案是在my web.config中为REST服务添加以下内容:

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS"/>
    </customHeaders>
  </httpProtocol>
</system.webServer>