2015-01-16 58 views
1

我工作的API managementexposing API using Javascript code 如果我去Developer portal和API結果check my url它給了我correct result像下面無法獲取使用javascript代碼

Response content 
[{ 
"ContactId":1, 
"Name":"Debra Garcia", 
"Address":"1234 Main St", 
}, 

{"ContactId":2, 
"Name":"Thorsten Weinrich", 
"Address":"5678 1st Ave W", 
}] 

but using javascript code I'm not getting anything Nor status error code :(
Js Code 
<script type="text/javascript"> 
    $(function() { 
     var params = { 

      'subscription-key': 'mykey', 
     }; 

     $.ajax({ 
      url: 'https://mydemo.azure-api.net/marketing/contacts?' + $.param(params), 
      type: 'GET', 
     }) 
     .done(function(data) { 
      alert("success"); 
     }) 
     .fail(function() { 
      alert("error"); 
     }); 
    }); 
</script> 

哪裏需要調試? enter image description here

+1

你得到什麼樣的錯誤? –

+1

也許是一個XSS問題? – Nano

+0

沒有錯誤:(什麼是跨站腳本問題? – Neo

回答

2

確保您使用正確的策略在API上啓用了CORS支持。 Azure documentation site有一個示例如何做到這一點(片段以下):

<cors> 
    <allowed-origins> 
     <origin>*</origin> <!-- allow any --> 
     <!-- OR a list of one or more specific URIs (case-sensitive) --> 
     <origin>http://contoso.com:81</origin> <!-- URI must include scheme, host, and port. If port is omitted, 80 is assumed for http and 443 is assumed for https. --> 
    </allowed-origins> 
</cors> 
+0

我在哪裏需要配置:O 我已經安裝了這個Install-Package Microsoft。 AspNet.WebApi.Cors – Neo

+0

此策略是通過Azure API管理的發佈者門戶添加的。 –