0
有一些实验来构建JavaScript应用程序,而不支持任何服务器端语言,如php,python ...只是与网络数据库层api的JavaScript。使用orchestrate.io,但HTML5 CORS需要严格的标题响应,如访问控制 - 允许来源。有没有办法建立一种应用程序步入DbaaS?Javascript应用程序避免服务器端语言
例如nginx配置为只运行www/index.html。 我们需要通过HTTP使用REST API获取.json数据。这是我们的博客文章。 JSON-P不能发送http头(?)。
谁知道这个?
设置:
nginx的
server {
...
root /usr/local/www
index index.html
...
}
的index.html
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
}
return xhr;
}
var xhr = createCORSRequest('GET', url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.withCredentials = true;
var url = 'https://api.service.io/article/1';
var xhr = createCORSRequest('GET', url);
xhr.onload = function() {
var responseText = xhr.responseText;
console.log(responseText);
// process the response.
};
xhr.onerror = function() {
console.log('There was an error!');
};
xhr.send();
,我需要发送基本身份验证的HTTP头......这就是所有
我不确定你的意思。这是您使用CORS orchestrate.io时遇到的特定问题吗?你能提供更多关于你设置的所有信息吗? – Stratus3D
这不是一个管弦乐的心愿单问题。有关将纯JavaScript与DBaas集成的更多信息。安装程序非常简单,就像从浏览器加载html一样。 –
我还是很困惑。 DBaas是数据库即服务的通用术语。也许您可以提供有关您的设置的详细信息(例如,Web服务器配置,Javascript代码示例)。这真的有助于看到一些示例代码在问题中产生了特定的错误。 – Stratus3D