我正在API management
和exposing API using Javascript code
工作
如果我转到Developer portal
和check my url
,它会给我correct result
,如下所示
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>
我需要调试的地方?
答案 0 :(得分: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>