Skip to content

Commit cbc9bb4

Browse files
committed
Added XDomainRequest Transport plugin for cross-domain AJAX support in MSIE >= 8.
Treat GET requests with a "_method" parameter of "DELETE" like DELETE requests for the Google App Engine and PHP implementations, as XDomainRequest only supports GET and POST.
1 parent 84b7a65 commit cbc9bb4

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
lines changed

application.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload Plugin JS Example 5.1.1
2+
* jQuery File Upload Plugin JS Example 5.1.2
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2010, Sebastian Tschan
@@ -18,6 +18,11 @@ $(function () {
1818
// Initialize the jQuery File Upload widget:
1919
$('#fileupload').fileupload();
2020

21+
// Load XDR library for cross-domain AJAX requests in MSIE >= 8:
22+
if (window.XDomainRequest) {
23+
$.getScript('jquery.xdr-transport.js');
24+
}
25+
2126
if (window.location.hostname === 'blueimp.github.com') {
2227
// Demo setting:
2328
$('#fileupload form').prop(

gae/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# jQuery File Upload Plugin GAE Example 1.0.1
3+
# jQuery File Upload Plugin GAE Example 1.1
44
# https://github.com/blueimp/jQuery-File-Upload
55
#
66
# Copyright 2010, Sebastian Tschan
@@ -105,6 +105,8 @@ def head(self):
105105
pass
106106

107107
def get(self):
108+
if (self.request.get('_method') == 'DELETE'):
109+
return self.delete()
108110
self.redirect(WEBSITE)
109111

110112
def post(self):

jquery.xdr-transport.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* jQuery XDomainRequest Transport Plugin 1.0
3+
* https://github.com/blueimp/jQuery-File-Upload
4+
*
5+
* Copyright 2011, Sebastian Tschan
6+
* https://blueimp.net
7+
*
8+
* Licensed under the MIT license:
9+
* http://creativecommons.org/licenses/MIT/
10+
*
11+
* Based on Julian Aubourg's ajaxHooks xdr.js:
12+
* https://github.com/jaubourg/ajaxHooks/
13+
*/
14+
15+
/*jslint unparam: true */
16+
/*global jQuery, window, XDomainRequest */
17+
18+
(function ($) {
19+
'use strict';
20+
if (window.XDomainRequest) {
21+
jQuery.ajaxTransport(function (s) {
22+
if (s.crossDomain && s.async) {
23+
if (s.timeout) {
24+
s.xdrTimeout = s.timeout;
25+
delete s.timeout;
26+
}
27+
var xdr;
28+
return {
29+
send: function (headers, completeCallback) {
30+
function callback(status, statusText, responses, responseHeaders) {
31+
xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop;
32+
xdr = null;
33+
completeCallback(status, statusText, responses, responseHeaders);
34+
}
35+
xdr = new XDomainRequest();
36+
// XDomainRequest only supports GET and POST:
37+
if (s.type === 'DELETE') {
38+
s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
39+
'_method=DELETE';
40+
s.type = 'GET';
41+
}
42+
xdr.open(s.type, s.url);
43+
xdr.onload = function () {
44+
callback(
45+
200,
46+
'OK',
47+
{text: xdr.responseText},
48+
'Content-Type: ' + xdr.contentType
49+
);
50+
};
51+
xdr.onerror = function () {
52+
callback(404, 'Not Found');
53+
};
54+
if (s.xdrTimeout) {
55+
xdr.ontimeout = function () {
56+
callback(0, 'timeout');
57+
};
58+
xdr.timeout = s.xdrTimeout;
59+
}
60+
xdr.send((s.hasContent && s.data) || null);
61+
},
62+
abort: function () {
63+
if (xdr) {
64+
xdr.onerror = jQuery.noop();
65+
xdr.abort();
66+
}
67+
}
68+
};
69+
}
70+
});
71+
}
72+
}(jQuery));

php/index.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* jQuery File Upload Plugin PHP Example 5.3
3+
* jQuery File Upload Plugin PHP Example 5.4
44
* https://github.com/blueimp/jQuery-File-Upload
55
*
66
* Copyright 2010, Sebastian Tschan
@@ -242,8 +242,11 @@ private function handle_file_upload($uploaded_file, $name, $size, $type, $error)
242242
}
243243

244244
public function get() {
245+
if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
246+
return $this->delete();
247+
}
245248
$file_name = isset($_REQUEST['file']) ?
246-
basename(stripslashes($_REQUEST['file'])) : null;
249+
basename(stripslashes($_REQUEST['file'])) : null;
247250
if ($file_name) {
248251
$info = $this->get_file_object($file_name);
249252
} else {

0 commit comments

Comments
 (0)