Reputation: 561
I want to use Azure Table storage REST api in javaScript. So I make call like this:
$.ajax({
type: "POST",
beforeSend: function (request)
{
request.setRequestHeader("contentType", "application/atom+xml;type=entry;charset=utf-8");
},
url: "http://mystorageaccountname.table.core.windows.net/TodoList()?sv=2012-02-12&se=2013-07-05T09%3A40%3A06Z&tn=Todo&sp=raud&spk=myid&epk=myid&sig=Z%2BrfC2HxxxBUqM3nt6sCjlSvttb6qqOY%2BBnbdPYV%2BzliA%3D&timeout=90",
contentType: "application/atom+xml",
dataType: "jsonp",
jsonpCallback:"jsonpCallback",
data: xmlString,
success: function (xhr) {
alert(xhr.statusCode);
}
});
I found the request type convert to get because jsonp not support post.. Then I found this threads:
How to upload a text string directly to Windows Azure Blob from the browser using javascript Accessing Windows Azure Queues from client side javascript/jquery
seems like if I host the webrole and tablestorage service with the same domain, I can use that code with datatype=xml.
How can I do that? Does akakin.appcloudapp.net akakin.table.core.windows.net is same domain? Or how can I use JS/JQuery call Azure mangement Rest API directly?
Upvotes: 2
Views: 2714
Reputation: 136336
Currently you can't call Azure Management API directly using JavaScript because CORS is not supported in Windows Azure. Support for CORS is coming soon in Windows Azure Storage. Apart from CORS, Windows Azure Table Storage will also support returning the data in JSON format. Once those 2 things are in place, you should be able to accomplish this.
For now you would need to rely on some kind of middle layer (either as a Windows Azure Cloud service or a Windows Azure Websites) to which you'll send requests through your JavaScript application and then this middle layer will interact with the storage to get the data. Since Windows Azure Table Storage only returns the data in XML format, you would then convert that data into JSONP format and return back to the client.
Upvotes: 3