dongmopu6734 2014-04-03 18:36
浏览 67
已采纳

远程上传(使用blueimp文件上传插件)

Remote upload: Upload files via a given URL.

I want to add a remote upload to my website using blueimp plugin. I found this link:https://gist.github.com/blueimp/5075976, but I use an external server to upload my files, so when I write this code, I get the error:

Uncaught SecurityError: Blocked a frame with origin "http://myExternalURL.com" from accessing a frame with origin "http://www.myMainWebsite.com". Protocols, domains, and ports must match. 

The part of the code with the url:

$('#remote-file-copy').on('submit', function (e) {
    e.preventDefault();
    var url = $(this).find('input').val(),
        iframe = $('<iframe src="javascript:false;" style="display:none;"></iframe>');
    if (url) {
        iframe
            .prop('src', 'http://I-USE-EXTERNAL-URL/remote-file-copy.php?url=' + encodeURIComponent(url))
            .appendTo(document.body);
    }
});

How can I fix it?

Thank you very much! and sorry for my English

  • 写回答

1条回答 默认 最新

  • duanjian9148 2014-04-08 04:56
    关注

    add this line right after <?php in remote-file-copy.php

    header("Access-Control-Allow-Origin: *");
    

    this will tell the browser to allow javascript from other origins to access content from your php file , if you only want to allow from your site you can also do this:

    header("Access-Control-Allow-Origin: http://yourmaindomain.com");
    

    more reading on this: MDN ,enable-cors.org, another question

    see also : chrome-blocks-different-origin-requests

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)