Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts

    passing callbacks thru ajax

    What is the best way (or is there one) to pass a pointer (say, to an object or function) through a jquery ajax call? I'm not talking about the server getting a clientside pointer, I'm talking about shoving a pointer in the ajax object so that the "done-func" can get the pointer when the ajax results are ready.

    for example...
    function foo()
    {
    ...
    var obj = new Object();
    $.post(whatever.php', {data: dataString}, donefunc);
    }

    function donefunc(res)
    {
    this.???? - need to get the "obj" (above) from here
    }

    I understand how to pass strings (incl json), but not pointers (via jquery ajax)
    Last edited by snoodle; 04-28-2009 at 08:02 AM.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    I'm guessing myself, but will this not work:

    $.post(whatever.php', {data: dataString}, function(){
    donefunc(obj);
    });

  • Users who have thanked Spudhead for this post:

    snoodle (04-29-2009)

  • #3
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i worked around the need to pass a pointer thru ajax (in this case) but jeez, yeah, i believe that will work. i know i shouldn't post questions after all night pgmming sessions. thank you.

  • #4
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Well, I worked around needing to pass a func pointer earlier, but now the situation has arisin again. So, consider the following...


    function SummonJQueryAJAX(donefunc)
    {
    ...
    $.post(whatever.php', {data: dataString}, theAjaxDoneFunc);
    }
    function theAjaxDoneFunc(res)
    {
    // "res" is typically the json'ed string passed in by SummonJQueryAJAX() and modified by
    // the server-side code

    So, what I want is something like, theAjaxDoneFunc(res, passedInDoneFunc), whereby I can gain access to that original function pointer (or object pointer or whatever).

  • #5
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Code:
    $.post(whatever.php', {data: dataString}, function(resp){donefunc(resp,obj);});
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #6
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank You!


  •  

    Posting Permissions

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