在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:jquery-form/form开源软件地址:https://github.com/jquery-form/form开源编程语言:JavaScript 89.9%开源软件介绍:jQuery FormOverviewThe jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX. The main methods, ajaxForm and ajaxSubmit, gather information from the form element to determine how to manage the submit process. Both of these methods support numerous options which allow you to have full control over how the data is submitted. No special markup is needed, just a normal form. Submitting a form with AJAX doesn't get any easier than this! CommunityWant to contribute to jQuery Form? Awesome! See CONTRIBUTING for more information. Code of ConductPlease note that this project is released with a Contributor Code of Conduct to ensure that this project is a welcoming place for everyone to contribute to. By participating in this project you agree to abide by its terms. Pull Requests NeededEnhancements needed to to be fully compatible with jQuery 3jQuery 3 is removing a lot of features that have been deprecated for a long time. Some of these are still in use by jQuery Form. Compatibility
Download
CDN<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js" integrity="sha384-qlmct0AOBiA2VPZkMY3+2WqkHtIQ9lSdAsAn5RUJD/3vA5MKDgSGcdmIv4ycVxyn" crossorigin="anonymous"></script> or <script src="https://cdn.jsdelivr.net/gh/jquery-form/[email protected]/dist/jquery.form.min.js" integrity="sha384-qlmct0AOBiA2VPZkMY3+2WqkHtIQ9lSdAsAn5RUJD/3vA5MKDgSGcdmIv4ycVxyn" crossorigin="anonymous"></script> APIjqXHRThe jqXHR object is stored in element data-cache with the var form = $('#myForm').ajaxSubmit({ /* options */ });
var xhr = form.data('jqxhr');
xhr.done(function() {
...
}); ajaxForm( options )Prepares a form to be submitted via AJAX by adding all of the necessary event listeners. It does not submit the form. Use // prepare all forms for ajax submission
$('form').ajaxForm({
target: '#myResultsDiv'
}); ajaxSubmit( options )Immediately submits the form via AJAX. In the most common use case this is invoked in response to the user clicking a submit button on the form. Use ajaxSubmit if you want to bind your own submit handler to the form. // bind submit handler to form
$('form').on('submit', function(e) {
e.preventDefault(); // prevent native submit
$(this).ajaxSubmit({
target: '#myResultsDiv'
})
}); OptionsNote: All standard $.ajax options can be used. beforeSerializeCallback function invoked before form serialization. Provides an opportunity to manipulate the form before its values are retrieved. Returning beforeSerialize: function($form, options) {
// return false to cancel submit
} beforeSubmitCallback function invoked before form submission. Returning beforeSubmit: function(arr, $form, options) {
// form data array is an array of objects with name and value properties
// [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
// return false to cancel submit
} beforeFormUnbindCallback function invoked before form events unbind and bind again. Provides an opportunity to manipulate the form before events will be remounted. The callback is invoked with two arguments: the jQuery wrapped form object and the options object. beforeFormUnbind: function($form, options) {
// your callback code
} filteringCallback function invoked before processing fields. This provides a way to filter elements. filtering: function(el, index) {
if ( !$(el).hasClass('ignore') ) {
return el;
}
} clearFormBoolean flag indicating whether the form should be cleared if the submit is successful dataAn object containing extra data that should be submitted along with the form.
dataTypeExpected data type of the response. One of: null, 'xml', 'script', or 'json'. The dataType option provides a means for specifying how the server response should be handled. This maps directly to jQuery's dataType method. The following values are supported:
delegationtrue to enable support for event delegation requires jQuery v1.7+ // prepare all existing and future forms for ajax submission
$('form').ajaxForm({
delegation: true
}); errorDeprecated forceSyncOnly applicable when explicity using the iframe option or when uploading files on browsers that don't support XHR2.
Set to iframeBoolean flag indicating whether the form should always target the server response to an iframe instead of leveraging XHR when possible. iframeSrcString value that should be used for the iframe's src attribute when an iframe is used. iframeTargetIdentifies the iframe element to be used as the response target for file uploads. By default, the plugin will create a temporary iframe element to capture the response when uploading files. This option allows you to use an existing iframe if you wish. When using this option the plugin will not attempt handling the response from the server. methodThe HTTP method to use for the request (e.g. 'POST', 'GET', 'PUT'). replaceTargetOptionally used along with the target option. Set to true if the target should be replaced or false if only the target contents should be replaced. resetFormBoolean flag indicating whether the form should be reset if the submit is successful semanticBoolean flag indicating whether data must be submitted in strict semantic order (slower). Note that the normal form serialization is done in semantic order except for input elements of successDeprecated
targetIdentifies the element(s) in the page to be updated with the server response. This value may be specified as a jQuery selection string, a jQuery object, or a DOM element. typeThe HTTP method to use for the request (e.g. 'POST', 'GET', 'PUT'). uploadProgressCallback function to be invoked with upload progress information (if supported by the browser). The callback is passed the following arguments:
urlURL to which the form data will be submitted. Utility MethodsformSerializeSerializes the form into a query string. This method will return a string in the format: var queryString = $('#myFormId').formSerialize(); fieldSerializeSerializes field elements into a query string. This is handy when you need to serialize only part of a form. This method will return a string in the format: var queryString = $('#myFormId .specialFields').fieldSerialize(); fieldValueReturns the value(s) of the element(s) in the matched set in an array. This method always returns an array. If no valid value can be determined the array will be empty, otherwise it will contain one or more values. resetFormResets the form to its original state by invoking the form element's native DOM method. clearFormClears the form elements. This method empties all of the text inputs, password inputs and textarea elements, clears the selection in any select elements, and unchecks all radio and checkbox inputs. It does not clear hidden field values. clearFieldsClears selected field elements. This is handy when you need to clear only a part of the form. File UploadsThe Form Plugin supports the use of XMLHttpRequest Level 2 and FormData objects on browsers that support these features. As of today (March 2012) that includes Chrome, Safari, and Firefox. On these browsers (and future Opera and IE10) files uploads will occur seamlessly through the XHR object and progress updates are available as the upload proceeds. For older browsers, a fallback technology is used which involves iframes. More Info ContributorsThis project has transferred from github.com/malsup/form, courtesy of Mike Alsup. LicenseThis project is dual-licensed under the LGPLv2.1 (or later) or MIT licenses: Additional documentation and examples for version 3.51- at: http://malsup.com/jquery/form/ |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论