[solved] Extended Request Class return empty string...

here you will find only solved Help topics

Moderator: 1.2 Moderators

[solved] Extended Request Class return empty string...

Postby AHHP on Tue Mar 02, 2010 6:34 am

Hello,

I'm trying to create a subclass of Request by Request.JSON pattern simply like below:
  1. Request.Novo = new Class({
  2.     Extends: Request,
  3.     options: {
  4.         method: 'POST',
  5.         evalScripts:true,
  6.         noCache:true,
  7.         onFailure: function(xhr) {
  8.                 if(console) {
  9.                         console.log('Request Failed. ResponseText: ' + xhr.responseText);
  10.                         if(console.dir) console.dir(xhr);
  11.                 }
  12.         }
  13.     },
  14.     initialize: function(options){
  15.         this.parent(options);
  16.     },
  17.     success: function(text){
  18.         this.onSuccess(text);
  19.     },
  20.     hasError: function(response){
  21.         if($type(response) == 'string')
  22.             response = new Element('div', {html:response}).getFirst();
  23.         if($type(response) == 'element')
  24.             return ( $chk(response.getElement('.hasError')) ) ? true : false;
  25.         return null;
  26.     }
  27. });

It works but always returns empty responseText on onSuccess event!


Regards,
AHHP
AHHP
 
Posts: 4
Joined: Tue Mar 02, 2010 6:14 am
Location: Immortal Persia

Re: Extended Request Class return empty string...

Postby wowenkho on Tue Mar 02, 2010 6:55 am

what's the reason behind the success method on line 17? i feel iffy about it. for one because onSuccess doesn't necessarily get fed with an argument that way.
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines

Re: Extended Request Class return empty string...

Postby AHHP on Tue Mar 02, 2010 7:13 am

The success method didn't exist. I compared the Class with Request.JSON and i thought maybe this method should call locally but no success....
AHHP
 
Posts: 4
Joined: Tue Mar 02, 2010 6:14 am
Location: Immortal Persia

Re: Extended Request Class return empty string...

Postby wowenkho on Tue Mar 02, 2010 7:24 am

that would've been an odd predicament. if you got onFailure, surely the Request.JSON class would've also had an onSuccess function, and actually it does. i think the problem here is the fact that you've dealt with the onSuccess method a little bit incorrectly. you would've been better off setting your onSuccess similar to how you've set your onFailure in the options tab. either that or you have set in your initialize method a this.addEvent('success').

  1. Request.Novo = new Class({
  2.     Extends: Request,
  3.     options: {
  4.         method: 'POST',
  5.         evalScripts:true,
  6.         noCache:true,
  7.         onFailure: function(xhr) {
  8.                 if(console) {
  9.                         console.log('Request Failed. ResponseText: ' + xhr.responseText);
  10.                         if(console.dir) console.dir(xhr);
  11.                 }
  12.         },
  13.        onSuccess: function(text)
  14.        {
  15.          //your onSuccess magic here.
  16.        }
  17.     },
  18.     initialize: function(options){
  19.         this.parent(options);
  20.     },
  21.    
  22.     hasError: function(response){
  23.         if($type(response) == 'string')
  24.             response = new Element('div', {html:response}).getFirst();
  25.         if($type(response) == 'element')
  26.             return ( $chk(response.getElement('.hasError')) ) ? true : false;
  27.         return null;
  28.     }
  29. });
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines

Re: Extended Request Class return empty string...

Postby AHHP on Tue Mar 02, 2010 7:33 am

Thank you buddy but my problem is not about success method. My Class with or without this method makes same result!
Unless putting this method (or event or option) is required for subclasses....
AHHP
 
Posts: 4
Joined: Tue Mar 02, 2010 6:14 am
Location: Immortal Persia

Re: Extended Request Class return empty string...

Postby wowenkho on Tue Mar 02, 2010 7:45 am

my point is that the problem you have with your responseText being empty is possibly in the way of how you've set/override your onSuccess method or not. for that matter, it would be nice if we know how you coded your onSuccess method in the class to begin with.
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines

Re: Extended Request Class return empty string...

Postby AHHP on Tue Mar 02, 2010 8:25 am

Thank you for your helps.
I tried it in a simple page and it worked, i seems problem was for my codes...
AHHP
 
Posts: 4
Joined: Tue Mar 02, 2010 6:14 am
Location: Immortal Persia


Return to Solutions

Who is online

Users browsing this forum: No registered users and 4 guests

cron