从Azure的Blob存储与jQuery查询JSON数据 [英] Query JSON data from Azure Blob Storage with jQuery

查看:174
本文介绍了从Azure的Blob存储与jQuery查询JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure的Blob存储一些数据。数据是JSON,它已被保存在应用程序/ JSON内容类型。

I have some data in an Azure blob storage. The data is JSON and it has been saved with the "application/json" content type.

我的应用程序将在myapp.com主办,包含CNAME为myapp.cloudapp.net域。我想我应该像storage.myapp.com那poins到我的Azure存储创建一个自定义域名。

My app would be hosted at "myapp.com", a domain that contains a CNAME to "myapp.cloudapp.net". I guess I should create a custom domain name like "storage.myapp.com" that poins to my Azure storage.

不过呢?我可以使用JSONP或其他方法,使JSON AJAX调用Azure存储?

But then? Can I use JSONP or other way to make JSON ajax calls to Azure storage?

怎么会是更好的方式来做到这一点?

How would be the better way to do this?

非常感谢。

推荐答案

好吧,显然的Azure Blob存储不支持JSONP通俗易懂,但它可以做到的。

Well, apparently Azure blob storage doesn't support JSONP straightaway, but it can be done.

例如,如果我这个JSON存储在Azure中的BLOB:

For example, if I store this JSON in an Azure blob:

{"Name":"Valeriano","Surname":"Tortola"}

和我尝试:

<script type="text/javascript">

    $.getJSON("https://myaccount.blob.core.windows.net/jsonptests/data?jsoncallback=?",
             function (data) {
                 alert(data.Name);
             });
</script>

这是行不通的。嗯,其实浏览器下载的数据,但也没有回电。因此,考虑JSONP是如何工作的,如果我保存这个JSON的回调函数:

It doesn't work. Well, actually the browser download the data but there is no call back. So, considering how JSONP works, if I save this JSON with the callback function:

dataCallback({"Name":"Valeriano","Surname":"Tortola"})

和我做的:

<script type="text/javascript">

    function dataCallback(data) {
        alert(data.Name);
    }
</script>

<script type="text/javascript" src="https://myaccount.blob.core.windows.net/jsonptests/data"></script>

然后 dataCallBack 得到执行:)缺点是回调函数名称必须HAR codeD,但总比没有好。

Then the dataCallBack get executed :) The disadvantage is that the callback function name has to be harcoded, but it's better than nothing.

快乐的日子,但如果任何人有一个更好的办法将是巨大的。

Happy days, but if anyone has a better way would be great.

干杯。

这篇关于从Azure的Blob存储与jQuery查询JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆