diff --git a/jquery.form.js b/jquery.form.js index b76477a4..701f5afc 100644 --- a/jquery.form.js +++ b/jquery.form.js @@ -72,7 +72,7 @@ feature.formdata = window.FormData !== undefined; var hasProp = !!$.fn.prop; // attr2 uses prop when it can but checks the return type for -// an expected string. this accounts for the case where a form +// an expected string. this accounts for the case where a form // contains inputs with names like "action" or "method"; in those // cases "prop" returns the element $.fn.attr2 = function() { @@ -89,8 +89,13 @@ $.fn.attr2 = function() { /** * ajaxSubmit() provides a mechanism for immediately submitting * an HTML form using AJAX. + * + * @param object|string options jquery.form.js parameters or custom url for submission + * @param object data extraData + * @param string dataType ajax dataType + * @param function onSuccess ajax success callback function */ -$.fn.ajaxSubmit = function(options) { +$.fn.ajaxSubmit = function(options, data, dataType, onSuccess) { /*jshint scripturl:true */ // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) @@ -103,8 +108,20 @@ $.fn.ajaxSubmit = function(options) { if (typeof options == 'function') { options = { success: options }; - } - else if ( options === undefined ) { + + } else if ( typeof options == 'string' || ( options === false && arguments.length > 0 ) ) { + options = { + 'url' : options, + 'data' : data, + 'dataType' : dataType, + }; + + if(typeof onSuccess == 'function') + { + options.success = onSuccess; + } + + } else if ( options === undefined ) { options = {}; } @@ -460,7 +477,7 @@ $.fn.ajaxSubmit = function(options) { var CLIENT_TIMEOUT_ABORT = 1; var SERVER_ABORT = 2; - + function getDoc(frame) { /* it looks like contentWindow or contentDocument do not * carry the protocol property in ie8, when running under ssl @@ -468,9 +485,9 @@ $.fn.ajaxSubmit = function(options) { * the protocol is know but not on the other two objects. strange? * "Same origin policy" http://en.wikipedia.org/wiki/Same_origin_policy */ - + var doc = null; - + // IE8 cascading access check try { if (frame.contentWindow) { @@ -506,8 +523,8 @@ $.fn.ajaxSubmit = function(options) { // take a breath so that pending repaints get some cpu time before the upload starts function doSubmit() { // make sure form attrs are set - var t = $form.attr2('target'), - a = $form.attr2('action'), + var t = $form.attr2('target'), + a = $form.attr2('action'), mp = 'multipart/form-data', et = $form.attr('enctype') || $form.attr('encoding') || mp; @@ -618,7 +635,7 @@ $.fn.ajaxSubmit = function(options) { if (xhr.aborted || callbackProcessed) { return; } - + doc = getDoc(io); if(!doc) { log('cannot access response document'); @@ -847,8 +864,20 @@ $.fn.ajaxSubmit = function(options) { * passes the options argument along after properly binding events for submit elements and * the form itself. */ -$.fn.ajaxForm = function(options) { - options = options || {}; +$.fn.ajaxForm = function(options, data, dataType, onSuccess) { + if (typeof options == 'string' || (options === false && arguments.length > 0)) { + options = { + 'url' : options, + 'data' : data, + 'dataType' : dataType, + }; + + if (typeof onSuccess == 'function') { + options.success = onSuccess; + } + } + + options = options || {}; options.delegation = options.delegation && $.isFunction($.fn.on); // in jQuery 1.3+ we can fix mistakes with the ready state @@ -964,7 +993,7 @@ $.fn.formToArray = function(semantic, elements, filtering) { if (!els || !els.length) { return a; } - + if ($.isFunction(filtering)) { var els = $.map(els, filtering); }