├── .gitignore ├── demo ├── .gitignore ├── spinner.gif ├── README ├── layout.css ├── server.js ├── client.js └── index.html ├── README └── jquery.iframe-transport.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /demo/spinner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/html/jquery-iframe-transport/master/demo/spinner.gif -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | jQuery Ajax transport plugin for iframe-based file uploads. For more 2 | information, see: 3 | 4 | http://cmlenz.github.com/jquery-iframe-transport/ 5 | -------------------------------------------------------------------------------- /demo/README: -------------------------------------------------------------------------------- 1 | This demo shows the basic transport functionality by allowing file uploads to 2 | be done asynchronously (that is, without a full page load). 3 | 4 | To run this example, you'll need node.js and npm, and the node modules 5 | "formidable" and "paperboy". 6 | 7 | $ npm install formidable paperboy 8 | $ node server.js 9 | 10 | Then load the URL http://localhost:8080/ and do some uploading. 11 | -------------------------------------------------------------------------------- /demo/layout.css: -------------------------------------------------------------------------------- 1 | html { background: #aaa; } 2 | body { background: #fff; border: 1px outset #999; color: #333; 3 | font: normal 90%/1.8 Arial,Helvetica,sans-serif; margin: 1em auto; 4 | padding: 10px 2em; width: 45em; 5 | } 6 | h1 { font-size: 140%; margin-bottom: 0; } 7 | #help { color: #666; font-size: smaller; font-style: italic; line-height: 1.4em; 8 | margin: 0 0 2em; 9 | } 10 | #help p { margin-top: 0; } 11 | form { background: #eee; border: 1px inset #ccc; margin: 1em 0; 12 | padding: 5px 0 5px 25px; 13 | } 14 | form.loading { background: #eee url(spinner.gif) 5px 50% no-repeat; } 15 | 16 | #filelist { list-style: none; margin: 1em 0; padding: 0; } 17 | #filelist li { padding-left: 25px; } 18 | #filelist li:nth-child(odd) { background: #f4f4f4; } -------------------------------------------------------------------------------- /demo/server.js: -------------------------------------------------------------------------------- 1 | var formidable = require("formidable"), 2 | http = require("http"), 3 | paperboy = require("paperboy"), 4 | path = require("path"); 5 | 6 | http.createServer(function(req, res) { 7 | if (req.url == "/upload" && req.method.toUpperCase() == "POST") { 8 | var form = new formidable.IncomingForm(), 9 | files = []; 10 | form.on("file", function(field, file) { 11 | files.push(file); 12 | }); 13 | form.on("end", function() { 14 | res.writeHead(200, {"Content-Type": "application/json"}); 15 | res.end(JSON.stringify({files: files})); 16 | }); 17 | form.parse(req); 18 | } else if (req.url == "/jquery.iframe-transport.js") { 19 | paperboy.deliver(path.dirname(__dirname), req, res) 20 | } else { 21 | paperboy.deliver(__dirname, req, res) 22 | } 23 | }).listen(8080, "127.0.0.1"); 24 | 25 | console.log("Server ready at http://localhost:8080/"); -------------------------------------------------------------------------------- /demo/client.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | "use strict"; 3 | 4 | $("form").on("change", ":file", function() { 5 | var form = $(this.form).addClass("loading"); 6 | $.ajax(form.prop("action"), { 7 | files: form.find(":file"), 8 | iframe: true, 9 | dataType: "json" 10 | }).always(function() { 11 | form.removeClass("loading"); 12 | }).done(function(data) { 13 | $.each(data.files, function(idx, file) { 14 | $("
This is a simple example showing a file upload field that gets 11 | transmitted asynchronously using the iframe transport. Just choose one or 12 | more files, and they will be uploaded to the server (but not stored). After 13 | one upload has completed, you can upload more files.
14 |Please note that this example needs to run via 15 | node.js, as uploads require a server-side 16 | component to work properly.
17 |