weixin_33713350 2017-03-27 16:41 采纳率: 0%
浏览 17

来自文件://的Ajax请求

I am having real difficulty knowing what to do. I have been reading some sources that are inferring that you cannot make ajax calls when launching an html file from the local file system (file:// in the url).

I have a html file on my desktop (ie in the browser url file://) containing the following ajax call:

$.ajax({
    type: "POST", // This for array
    url: "http://www.mywebsite.com/exclude.php",
    async: true,
    cache: false,
    crossDomain: true, // This needs to be true for other people

    success: function (data) {
        var json = jQuery.parseJSON(data);
        // Use json in interesting ways
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        // Silent error
    }
});

My php file on my server is basic:

<?php
header("Access-Control-Allow-Origin: *"); // To allow cross domain
$KeyCodeStatics_BlackList = ["181K2", "4V419"];
echo json_encode($KeyCodeStatics_BlackList);
?>

Some are suggesting ajax calls are not allowed from an html file launched in the local file system (file:// in url).

The errors I am getting:

 Origin file: not found in Access-Control-Allow-Origin header.

and

XMLHttpRequest: Network Error 0x80700013, Could not complete the operation due to error 80700013.

How can I overcome this? I need to make an async call to /www.mywebsite.com/exclude.php from the html file from my local file system.

Note: It is not just me that has to do it, it is every end-user that uses this html file. So this means I cannot ask them to change security settings on their browser.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
    • ¥15 不小心不正规的开发公司导致不给我们y码,
    • ¥15 我的代码无法在vc++中运行呀,错误很多
    • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
    • ¥30 ppOCRLabel导出识别结果失败