试图从Chrome浏览器本地的.html访问JSON API浏览器、Chrome、html、API

由网友(欲望难止)分享简介:我已经建立了一个API,而我会试图从在Chrome测试.html文件访问。我米通过文件访问文件:/// ......而我得到的本地文件系统的限制。我已经启用了我的API跨起源请求访问,但我得到了以下的,当我尝试访问它:I have built an API and I m trying to access it fr...

我已经建立了一个API,而我会试图从在Chrome测试.html文件访问。我米通过文件访问文件:/// ......而我得到的本地文件系统的限制。我已经启用了我的API跨起源请求访问,但我得到了以下的,当我尝试访问它:

I have built an API and I m trying to access it from a test .html file in Chrome. I m accessing the file through file:///... and I get the local filesystem restrictions. I have enabled cross origin request access on my api but I get the following when I try to access it:

XMLHtt prequest无法加载的http://。方法未定义   不受访问控制 - 允许 - 方法允许的。

XMLHttpRequest cannot load http://. Method undefined is not allowed by Access-Control-Allow-Methods.

请求/响应头如下:

和javascript的code我米使用如下:

and the javascript code I m using is as follows:

var xmlhttp;
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        if (params.success) params.success(xmlhttp.responseText);
    } else if (xmlhttp.readyState == 4) {
        if (params.error) params.error(xmlhttp, xmlhttp.status, xmlhttp.responseText);
    }
};

xmlhttp.open(params.method, params.url, true);
xmlhttp.setRequestHeader('Content-Type', 'application/json');
xmlhttp.setRequestHeader('Accept', 'application/json, text/javascript, */*; q=0.01');

if (params.data) xmlhttp.send(params.data);
else xmlhttp.send();

如果我用$ .getJSON从jQuery的API调用工作正常,但我不希望出现这种情况。它必须是纯JavaScript。什么任何想法可能是错误的?

If I use $.getJSON from jquery the api call works fine but I dont want that. It needs to be pure javascript. Any ideas on what could be wrong?

推荐答案

对不起。我从来不问,如果你需要它来测试又名调试或生产

此安全参数打开你的浏览器:

open your chrome with this security param:

C: **** 的chrome.exe铬浏览器 - 禁用网络安全

镀铬的:

C: **** 的chrome.exe谷歌Chrome浏览器 - 禁用网络安全

我使用铬,但它应与镀铬工作了。

I'm using chromium but it's should work with chrome too..

阅读全文

相关推荐

最新文章