2 * jQuery plugin for posting form including file inputs.
4 * Copyright (c) 2010 - 2011 Ewen Elder
6 * Licensed under the MIT and GPL licenses:
7 * http://www.opensource.org/licenses/mit-license.php
8 * http://www.gnu.org/licenses/gpl.html
10 * @author: Ewen Elder <ewen at jainaewen dot com> <glomainn at yahoo dot co dot uk>
11 * @version: 1.1.1 (2011-07-29)
17 $('input[type=\"file\"]').each(function(i
, it
) {
18 $(it
).closest('form').attr('enctype', 'multipart/form-data').attr('encoding', 'multipart/form-data');
21 $.fn
.iframePostForm = function (options
)
29 options
= $.extend({}, $.fn
.iframePostForm
.defaults
, options
);
33 if (!$('#' + options
.iframeID
).length
)
35 $('body').append('<iframe id="' + options
.iframeID
+ '" name="' + options
.iframeID
+ '" style="display:none" />');
39 return $(this).each(function ()
45 element
.attr('target', options
.iframeID
);
49 element
.submit(function ()
51 // If status is false then abort.
52 status
= options
.post
.apply(this);
60 iframe
= $('#' + options
.iframeID
).load(function ()
62 response
= iframe
.contents().find('body');
67 returnReponse
= $.parseJSON(response
.html());
72 returnReponse
= response
.html();
76 options
.complete
.apply(this, [returnReponse
]);
78 iframe
.unbind('load');
81 setTimeout(function ()
91 $.fn
.iframePostForm
.defaults
=
93 iframeID
: 'iframe-post-form', // Iframe ID.
94 json
: false, // Parse server response as a json object.
95 post : function () {}, // Form onsubmit.
96 complete : function (response
) {} // After response from the server has been received.