Giter Club home page Giter Club logo

fileuploadcrossdomain's Introduction

简介 :


跨域ajax文件上传,目前版本只能一次上传一个文件。
使用Html5的postMessage提供跨域之间的消息传递。
注意console里面的输出调整项目。

测试设置 :

把setting.nginx.conf配置加入到nginx的配置里面
修改nginx配置把root指向当前的目录,即跟这个ReadMe.md同级的目录
设置 /etc/hosts 加入一下

127.0.0.1 file.domain.xyz dev.domain.com

其中dev.domain.com为测试业务域名
file.domain.xyz为文件存储服务提供者的域名
启动nginx
访问http://dev.domain.com/test/demo.php

加载方法 :

1.业务页面中先加载Jquery库
2.在JQuery的加载代码后面放入

<script type="text/javascript">
    var storageHost="file.domain.xyz";
    $.getScript(storageHost+"/utils/upload/v1/embedded.js",function(){});
</script>

其中storageHost填入文件存储服务提供者的域名,这里是file.domain.xyz,storageHost也是embedded.js里面需要用到的变量,因此他的名字不能更改。

对指定标签绑定click事件 :

$("#inputId").click(function(){superUpload('inputId');});
默认回调函数只更改传递的标签inputId的value值为upload.php的返回值。

eg:
    $("#preview1").click(function(){
        superUpload(this.id);
    });
    //其中superUpload为默认可用的回调函数
    //更新服务器返回的值到对应的input#id的value属性中

参考/test/demo.php写法

扩展 :

setUploadCallbackFunction(callback) 可设置自定义回调函数
需在绑定的click事件触发之前执行;

fileuploadcrossdomain's People

Contributors

kimffy24 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.