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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。