This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildSubmitHandler(ajaxOptions) { | |
function submitViaAJAX(event) { | |
var data = $.extend( {}, ajaxOptions.data, $form.serialize() ), | |
options = $.extend({}, { | |
url: $form.attr('action'), | |
type: $form.attr('method'), | |
}, ajaxOptions, { data: data }); | |
$.ajax(options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array Iteration: | |
myArray = [ 'foo' ]; | |
myArray.forEach(function(x) { console.log(x); }); | |
// prints "foo" | |
// Object Keys: | |
myObject = { foo: 'bar', baz: 'quux' }; | |
Object.keys(myObject); // [ "foo", "baz" ] | |
// Object Iteration Helper (context is optional) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
ajaxForm('.ajax-form'); | |
}) | |
var ajaxForm = function(query) | |
{ | |
$(query).submit(function(event) { | |
event.preventDefault(); | |
var $form = $(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#file').change(function() { | |
$("#uploader").ajaxForm({iframe: true, success: success}).submit(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('form').submit(e) { | |
e.preventDefault(); | |
$(this).ajaxSubmit({ | |
beforeSubmit: function() { | |
// code to show spinner | |
}, | |
complete: function() { | |
// code to hide spinner | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.ajax-forms').submit(onAjaxFormSubmit); | |
var onAjaxFormSubmit = function(evt) { | |
evt.preventDefault(); | |
var $form = $(this); | |
var data = $form.serialize(); | |
var path = $form.attr('action'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Canonical ASP.NET MVC usage | |
// site.css | |
.ajax-progress-show, .ajax-progress-error { display: none; } | |
// index.cshtml | |
@Html.Partial("partial",new SampleModel()) | |
// partial.cshtml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var spinner = $('#ajax-spinner'); | |
$(document).ajaxSend(function() { | |
$('input[type=submit]').attr('disabled', 'disabled'); | |
$('#warningBox').hide(); | |
spinner.show() | |
}).ajaxStop(function() { | |
$('input[type=submit]').removeAttr('disabled'); | |
spinner.hide() | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $form = $('#your-form'); | |
$form.on('submit', function(evt){ | |
evt.preventDefault(); | |
$.ajax({ | |
url: $form.attr('action'), | |
type: $form.attr('method'), | |
data: $form.serialize(), | |
success: function(data){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$(".ajax_request").bind('ajax:before', function(evt, status, data, xhr) { | |
showAjaxLoading(); | |
}); | |
$(".ajax_request").bind('ajax:complete', function(evt, status, data, xhr) { | |
hideAjaxLoading(); | |
}); |
OlderNewer