Changeset 1717


Ignore:
Timestamp:
2010-09-30 12:49:43 (3 years ago)
Author:
mpo
Message:

fixes #368
Tracking the last issues request for refresh-options avoids updating the options with results that came in too late.
(this should allow for better responsiveness then the async: false approach suggested in the issue)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/field.js

    r1648 r1717  
    203203            var uri = this.uri.expand(this.uriContext); 
    204204            var me = this; 
    205             var callback = function( data) { 
    206      
    207                 me.parseOptions(data); 
     205            var onSuccess = function( data, status, xhr) { 
     206                if (xhr && me.lastXhr == xhr) { //ignore responses that are not linked to the last request  
     207                    me.parseOptions(data); 
     208                    me.lastXhr = null; 
     209                } 
    208210            }; 
    209             var errorcallback = function( data) { 
    210                  
    211                 me.clearOptions(data); 
     211            var onError = function( xhr, status, err) { 
     212                if (xhr && me.lastXhr == xhr) {  
     213                    me.clearOptions(); 
     214                    me.lastXhr = null; 
     215                } 
    212216            }; 
    213217 
    214             $.ajax( { 
     218            // assign lastXhr to make sure only the return of this last one is accepted  
     219            this.lastXhr = $.ajax( { 
    215220                // take async setting from setup 
    216                 type :"GET", 
    217                 url :uri, 
    218                 processData :false, 
    219                 dataType :"json", 
    220                 success :callback, 
    221                 error :errorcallback, 
    222                 beforeSend: function(xhr) { 
    223                 // setting datatype to json should be enough, unfortunately 
    224                 // the restlet content negotiation chokes on the resulting 
    225                 // accept header: application/json, text/javascript, */* 
    226                 // and doesn't prefer the json variant. 
    227                 // see issue #95 
    228                 xhr.setRequestHeader("Accept", "application/json"); 
     221                type       : "GET", 
     222                url        : uri, 
     223                processData: false, 
     224                dataType   : "json", 
     225                success    : onSuccess, 
     226                error      : onError, 
     227                beforeSend : function(xhr) { 
     228                    // setting datatype to json should be enough, unfortunately 
     229                    // the restlet content negotiation chokes on the resulting 
     230                    // accept header: application/json, text/javascript, */* 
     231                    // and doesn't prefer the json variant. 
     232                    // see issue #95 
     233                    xhr.setRequestHeader("Accept", "application/json"); 
    229234                } 
    230235            }); 
     
    304309      * @param {Array} data 
    305310      */ 
    306      Options.prototype.clearOptions = function( data) { 
     311     Options.prototype.clearOptions = function( ) { 
    307312 
    308313         this.set([], []); 
Note: See TracChangeset for help on using the changeset viewer.