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 metadata提取的PDF元数据,如何转换为一个Excel
    • ¥15 关于arduino编程toCharArray()函数的使用
    • ¥100 vc++混合CEF采用CLR方式编译报错
    • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
    • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
    • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
    • ¥50 如何openEuler 22.03上安装配置drbd
    • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
    • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
    • ¥15 Windows11, backspace, enter, space键失灵