I would like to ask how to create a page with a lot of ajax calls. for example, 10 ajax calls on one page that have a CRUD function ..
I currently have such a custom setup:
$('[data-ajaxform]').submit(function(event) {
event.preventDefault();
event.stopImmediatePropagation();
if(!$(this).parsley().validate()){
return false;
}
var $this = $(this),
url = $this.attr('action'),
method = $this.attr('method'),
container = $this.data('container');
if(typeof container !== undefined && container !== false)
container = '.panel-body';
$.ajax({
url: url,
type: method,
dataType: 'json',
data: $this.serialize(),
beforeSend: function(){
$this.find(container).append('<div class="indicator show"><span class="spinner spinner1"></span></div>')
},
})
.done(function(data) {
setTimeout(function() {
$this.find(container).prepend(data.responseText);
}, 1000);
$this.trigger('reset');
hasValue($this.data('ajaxform'))
})
.fail(function(data) {
setTimeout(function() {
$this.find(container).prepend(data.responseText);
}, 1000);
})
.always(function(data) {
setTimeout(function() {
$this.find('.indicator').remove();
}, 1000);
});
return false;
});
Can you guys suggest me what good practice to implement with this or some articles that can help me? Many thanks
source
share