haha... how can't I figure that out :) l learn one.
however I was able to use the .ajaxSetup to pass the "this" pointer
during version 1.2.3.
is there a need to fix that?

Thanks,
sglai


2008/9/25 Ariel Flesler <[EMAIL PROTECTED]>:
> Or
>
> var A = function() {};
> A.prototype = {
>   get: function(id) {
>       $.ajax({
>            type : "GET",
>           caller:this,
>           ....
>           success : function(xml) {
>              this.caller.status = ...
>           }
>       })
>   };
> }
>
> Note that unless you set the option 'async' to false, the request won't be
> synchronous, so you can't evaluate the status "right after".
>
> On Wed, Sep 24, 2008 at 11:59 AM, Jörn Zaefferer
> <[EMAIL PROTECTED]> wrote:
>>
>> Use a closure:
>>
>> var A = function() {};
>> A.prototype = {
>>   this.status; // hold the http response status
>>   get: function(id) {
>>       var self = this;
>>       $.ajax({
>>       type : "GET",
>>       ....
>>       success : function(xml) {
>>                      self.status = ...
>>                      }
>>       }) };
>> }
>>
>> Jörn
>>
>> On Wed, Sep 24, 2008 at 4:51 PM, sglai <[EMAIL PROTECTED]> wrote:
>> >
>> >
>> > um..let me try again.
>> > Say you have a constructor A and you create objects from it:
>> >
>> > var myobj = new A();
>> > myobj.get("file.xml");
>> > var msg = myobj.status == 200 ? "yes" : "oh no";
>> >
>> > var myobj2 = new A();
>> > myobj2.get("file2.xml");
>> > var msg = myobj2.status == 200 ? "yes 2" : "oh no 2";
>> >
>> > So, the A could be like this:
>> >
>> > var A = function() {};
>> > A.prototype = {
>> >    this.status; // hold the http response status
>> >    get: function(id) { $.ajax({
>> >        type : "GET",
>> >        ....
>> >        success : function(xml) {
>> >                       // this in here is the XHR object.
>> >                       // ??? how do i pass the status (200) to
>> > "this.status"
>> >                       }
>> >        }) };
>> > }
>> >
>> > You see the "status" is an object property.
>> > I like to initialize this property when the ajax return success.
>> > What is the right way to do so?
>> >
>> >
>> > On Sep 23, 2:23 am, Ariel Flesler <[EMAIL PROTECTED]> wrote:
>> >> You can add custom attributes to $.ajax's object (thus to ajaxSetup).
>> >> 'data' is likely to misbehave behave that value is sent to the server,
>> >> and in some cases it has to be forcedly set to null to avoid sending
>> >> both POST and GET vars.
>> >>
>> >> If you use any other key, it should work alright.
>> >>
>> >> As a sidenote, your specific example seems pointless. Because you're
>> >> setting mydata each time before calling $.ajax, so you can simply add
>> >> it to $.ajax.
>> >>
>> >> --
>> >> Ariel Fleslerhttp://flesler.blogspot.com
>> >>
>> >> On Sep 21, 11:26 am, "sui-sing Lai" <[EMAIL PROTECTED]> wrote:
>> >>
>> >> > ok, I tried to pass "this" object to ajax callback.
>> >> > I refer to jQuery doc and find out that I can pass it to via
>> >> > $.ajaxSetup( { mydata : this } ).
>> >> > code go like this:
>> >>
>> >> > var myObj = function() {
>> >> >   $.ajaxSetup({mydata:this});
>> >> >   $.ajax({
>> >> >     ....
>> >> >     success:function(xml){ this.mydata.status = 200}
>> >> >   }
>> >>
>> >> > }
>> >>
>> >> > Hope this is better.
>> >>
>> >> > Thanks,
>> >> > sglai
>> >>
>> >> > 2008/9/21 Jörn Zaefferer <[EMAIL PROTECTED]>:
>> >>
>> >> > > Could you be more specific about the actual issue?
>> >> > > $.ajaxSetup({mydata:this}) doesn't make much sense.
>> >>
>> >> > > Jörn
>> >>
>> >> > > On Sun, Sep 21, 2008 at 10:58 AM, sglai <[EMAIL PROTECTED]>
>> >> > > wrote:
>> >>
>> >> > >> Hi,
>> >>
>> >> > >> Happen to find this problem. Does release test case cover this?
>> >>
>> >> > >> Regards,
>> >> > >> sglai
>> > >
>> >
>>
>>
>
>
>
> --
> Ariel Flesler
> http://flesler.blogspot.com
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to