demo/static/update_user.js
function ajax_return(data, status, xhr) {
    // If the update was successfull
    if (data.ok) {
	// Forget old value
	this.removeData('old-value');
	// Add a green V to the right
	this.parent().next()
	    .off('click')
	    .html('V')
	    .css('color', 'LimeGreen')
	    .attr('title', 'Update OK');

	// If we modified the id
	if (this.attr('id') == 'id') {
	    var url = '/user?id=' + encodeURIComponent(this.val());
	    // update the link in the header...
	    $('#user-link')
		.text(this.val())
		.attr('href', url);
	    // ...and the url in the adress bar
	    history.pushState(null, null, url);
	}
    } else {
	// Add a red X to the right
	var elem = this;
	elem.parent().next()
	    .html('X')
	    .css('color', 'red')
	    .attr('title', data.message)
	    .one('click', function() { 	  // if the X is clicked, restore original data
		elem.val(elem.data('old-value'));
		$(this)
		    .empty()
		    .removeAttr('title');
	    });
    }
    // reactivate the control
    this.prop('disabled', false);
}
function ajax_return(data, status, xhr) {
    // If the update was successfull
    if (data.ok) {
	// Forget old value
	this.removeData('old-value');
	// Add a green V to the right
	this.parent().next()
	    .off('click')
	    .html('V')
	    .css('color', 'LimeGreen')
	    .attr('title', 'Update OK');

	// If we modified the id
	if (this.attr('id') == 'id') {
	    var url = '/user?id=' + encodeURIComponent(this.val());
	    // update the link in the header...
	    $('#user-link')
		.text(this.val())
		.attr('href', url);
	    // ...and the url in the adress bar
	    history.pushState(null, null, url);
	}
    } else {
	// Add a red X to the right
	var elem = this;
	elem.parent().next()
	    .html('X')
	    .css('color', 'red')
	    .attr('title', data.message)
	    .one('click', function() { 	  // if the X is clicked, restore original data
		elem.val(elem.data('old-value'));
		$(this)
		    .empty()
		    .removeAttr('title');
	    });
    }
    // reactivate the control
    this.prop('disabled', false);
}
function ajax_return ( data , status , xhr ) { // If the update was successfull if ( data . ok ) { // Forget old value this . removeData ( 'old-value' ) ; // Add a green V to the right this . parent ( ) . next ( ) . off ( 'click' ) . html ( 'V' ) . css ( 'color' , 'LimeGreen' ) . attr ( 'title' , 'Update OK' ) ; // If we modified the id if ( this . attr ( 'id' ) == 'id' ) { var url = '/user?id=' + encodeURIComponent ( this . val ( ) ) ; // update the link in the header... $ ( '#user-link' ) . text ( this . val ( ) ) . attr ( 'href' , url ) ; // ...and the url in the adress bar history . pushState ( null , null , url ) ; } } else { // Add a red X to the right var elem = this ; elem . parent ( ) . next ( ) . html ( 'X' ) . css ( 'color' , 'red' ) . attr ( 'title' , data . message ) . one ( 'click' , function ( ) { // if the X is clicked, restore original data elem . val ( elem . data ( 'old-value' ) ) ; $ ( this ) . empty ( ) . removeAttr ( 'title' ) ; } ) ; } // reactivate the control this . prop ( 'disabled' , false ) ; }
This function is called when the AJAX request returns
This function is called when the AJAX request returns