Repository navigation
The plugin's source is now split into modules, and this release fixes a long list of bugs found while pinning down its behavior. No breaking changes are intended. Behavior changes only where the old behavior was a bug or differed from a native form submission, so read the lists below if your code relied on any of them. jQuery 1.7.2 or later is still supported. Every change is tested on jQuery 1.7.2, 3.7.1 and 4.0.0.
New
delegation: "<selector>"limitsajaxFormdelegation to forms that match a selector (#353).delegation: trueis unchanged, but it now logs a warning on jQuery 3 and later, where it binds every form on the page.ajaxFormUnbind()also removes delegated bindings, andajaxFormUnbind(selector)removes one of them.requestFormat: "json"sends the form as a JSON body (#545). The idea came from #557 by @zhangciwu.errorandcompleteaccept arrays of functions, as in$.ajax.ajaxSubmiton jQuery's slim build throws a clear error (#541) instead of failing later.
Deprecations
These log a warning once per page when $.fn.ajaxSubmit.debug is on, and 5.0 will remove them.
clearInputs: useclearFields.$.fn.attr2: use.prop()or.attr().ajaxFormon an empty selection before the DOM is ready, which queues the binding: call it inside$(fn), or usedelegation: "<selector>".- The iframe transport chosen automatically when the browser has no
FormData: setiframe: true. - The
closeKeepAliveoption, a workaround for Safari 3 and 4. - jQuery older than 3.5. 5.0 will need jQuery 3.5 or later.
enable and selected are kept.
Fixes: submission and transports
- Every transport uses the same request method.
methodwins overtype, and it is read afterbeforeSubmit. - A url of
falseor""submits to the form'saction. - A string
dataoption is treated as a query string. thisin callbacks is the caller'scontextobject, not a copy of it.successruns whentargetmatches nothing.beforeSendreturningfalsecancels a FormData upload, as it already did on the other transports.uploadProgresskeeps a customxhrfactory, and reports position 0 and 0% for a progress event with nothing loaded.- A multipart
enctypeis recognized regardless of case and surrounding spaces. - File uploads with GET put file names in the URL, never
[object File].
Fixes: iframe uploads
- Events fire in the same order as
$.ajax, and abeforeSendveto ends the global events withajaxStop. - Every upload settles exactly once, including when an exception is thrown.
abort()before the delayed post cancels it. - Uploads started in the same millisecond use different frames, and an
iframeTargetwithout a name receives the upload. dataTypeis read case-insensitively.- A frame that is not in the document fails with an error instead of opening a new window.
- The form's attributes are restored exactly after the upload (#380).
- With
closeKeepAlive, controls disabled inbeforeSubmitare posted and re-enabled afterwards.
Fixes: serialization, fields and form members
- Controls named like form members (
getAttribute,ownerDocument,tagName,reset,clkand others) no longer break the plugin. A control namedparentNodethrows a clear error. - The contents of a disabled
<fieldset>or<optgroup>are not sent.semantic: truesends only controls the form owns. Namedfieldset,outputandobjectelements are not sent. A lone CR in a value is sent as CRLF on every jQuery version. ajaxFormsends the browser'sSubmitEvent.submitterwhen no click was captured, for example after pressing Enter or callingrequestSubmit(button).resetFormmatches a native reset. It keeps the values of checkboxes, radios, hidden inputs and buttons, empties file inputs instead of throwing, and selects the last default option of a single select.clearFormandclearFieldscleardatetime-localinputs.
Docs
- How to sanitize a response inserted by
target, withdataFilter(jQuery 3.5 and later). - The list of options that must come only from trusted code, not from user input.
- What an iframe upload response has to look like.
Build
- The classic build runs its whole factory in strict mode. The same three
distfiles are published.
Known, not changed in 4.5.0
- String values of
targetandiframeTargetare still passed to$(), so pass only selectors from your own code (see the trusted options list). 4.6.0 will look them up only as selectors.
Full changelog: v4.4.0...v4.5.0