Page 14 of 42 FirstFirst ... 4121314151624 ... LastLast
Results 131 to 140 of 414

Thread: [ext-basex/$JIT 4.0 adapter extensions] Ajax enhancements and more.

  1. #131
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966
    Vote Rating
    15
      0  

    Default

    Quote Originally Posted by mubenchi View Post
    i want to use Ext.lib.Ajax.onStatus to deal with the situation that the server check session timeout,and give a http 302 or 401 and so on status.could any one give me a help?thanks
    @mubenchi -- Have a look at this post (and beyond, on this thread) for some sample usage and other things you may need to consider as well.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  2. #132
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966
    Vote Rating
    15
      0  

    Default responseJSON, the needs of the many....

    Quote Originally Posted by ZooKeeper View Post
    I'm also greatly in favor of responseJson. It'll be a lifesaver, since I have to decode it in EVERY callback.
    Relying that much on content type is probably not such a good idea, since not everyone can set it.
    @Zookeeper -- While I understand where you're coming from with that, it's somewhat dangerous to be evaling anything that comes along in a response.

    Anywho:

    I've given all this a bit of thought (during a short vacation )...

    There are a number of issues that arise when making assumptions about JSON handling, and I thought I would throw out a code frag for review/feedback for sensibility:

    Code:
    Ext.apply(Ext.lib.Ajax, {
    
      decodeJSON : Ext.decode,  //optional custom JSON decoder implementation
    
      reCtypeJSON : /\/json/gi , 
    
      createResponseObject : function(o, callbackArg, isAbort){
            var obj = {responseXML   :null,
                       responseText  :'',
                       responseStream : null,
                       responseJSON  : null,
                       getResponseHeader : {},
                       getAllResponseHeaders : ''
                       };
    
             // some existing code omitted for clarity......
    
              if(o.options.isJSON || this.reCtypeJSON.test( headerObj['Content-Type'] || "" ){
                 try{
                      obj.responseJSON = this.decodeJSON(obj.responseText);
                   } catch(exJSON){ 
                      o.status.isError = true;
                      o.status.error = exJSON;
                     //Raise lib.Ajax Exception Event 
                      if(this.events){
                         this.fireEvent('exception',o ,obj, callback, isAbort, exJSON);
                      }
                     
                   }
              }
              .........
      });
    Some notes on flexibility:

    1) It comes at a price. Content-Type header evaluation could be expensive.
    2) Script injection is a risk here, so an optional Ext.lib.Ajax.decodeJSON function permits custom JSON "Crockford-scrutiny" if your implementation demands it (otherwise it falls back to the standard Ext.decode -- a simple eval).
    3) The regex Content-Type test pattern (reCtypeJSON ) can be adjusted to suite your needs as well.
    4) request.options.isJSON is a request hint that the response will be JSON, thus it would preclude the need to adapt server code to send either text/json or application/json Content-type response headers on each response (altho in practice, the new RFC says you SHOULD).

    Food for thought.
    Last edited by hendricd; 17 Jul 2008 at 3:06 AM. Reason: added decodeJSON default and exception handling
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #133
    Sencha User mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
      0  

    Default

    might be easier to just set
    Code:
    decodeJSON: Ext.decode, // custom json decoder function -- defaults to Ext.decode
    then you could do away with
    Code:
    this.decodeJSON  || (this.decodeJSON = Ext.decode);
    other than that, it looks good -- as usual

  4. #134
    Sencha User
    Join Date
    Mar 2007
    Posts
    49
    Vote Rating
    0
      0  

    Default

    hendricd
    i'm using DOM method, because i use Adobe AIR and i can't use eval function

  5. #135
    Ext JS Premium Member
    Join Date
    Jul 2007
    Posts
    219
    Vote Rating
    3
      0  

    Default

    Quote Originally Posted by mystix View Post
    might be easier to just set
    Code:
    decodeJSON: Ext.decode, // custom json decoder function -- defaults to Ext.decode
    then you could do away with
    Code:
    this.decodeJSON  || (this.decodeJSON = Ext.decode);
    other than that, it looks good -- as usual
    I cann't agree more. If you are expecting Json then if it decode fails then it's either not a 200 code or something else which is an error anyway (there should be a param showing that json was successfully parsed). The other issue is if you want to figure out what error was it, parsing error, timeout or non200 code.

    For myself I can say that I'd be happy with decodeJSON param and flag that it was successfully parsed or not.

  6. #136
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966
    Vote Rating
    15
      0  

    Default

    See Code sample revised -- Thx Mystix.

    Quote Originally Posted by ZooKeeper View Post
    I cann't agree more. If you are expecting Json then if it decode fails then it's either not a 200 code or something else which is an error anyway (there should be a param showing that json was successfully parsed). The other issue is if you want to figure out what error was it, parsing error, timeout or non200 code.

    For myself I can say that I'd be happy with decodeJSON param and flag that it was successfully parsed or not.
    @ZooKeeper -- HTTP status and timeout are already handled elsewhere in the basex stack.
    See the revised code that adds the exception event when JSON decoding fails.

    Also, if(response.responseJSON !== null) it processed a good JSON response.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  7. #137
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966
    Vote Rating
    15
      0  

    Default responseJSON revisions...

    posted to svn/trunk.

    Lemme know how it goes.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  8. #138
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966
    Vote Rating
    15
      0  

    Default

    Quote Originally Posted by Digital God View Post
    hendricd
    i'm using DOM method, because i use Adobe AIR and i can't use eval function
    @Digital God -- I'm not clear on what you are attempting here?

    Are you trying to load a text file (what?) with a <script> tag(method:'DOM')? You don't have any control over response character-set from within the browser. The server must comply with your encoding wishes.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  9. #139
    Ext JS Premium Member
    Join Date
    Jul 2007
    Posts
    219
    Vote Rating
    3
      0  

    Default

    There's a parentesis missing on the line
    if(o.options.isJSON || (this.reCtypeJSON && this.reCtypeJSON.test( headerObj['Content-Type'] || "" ) )){

  10. #140
    Sencha User
    Join Date
    Mar 2007
    Posts
    49
    Vote Rating
    0
      0  

    Default

    2hendricd
    forget it, i've found my mistake))

Page 14 of 42 FirstFirst ... 4121314151624 ... LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •